File: nws.postinst

package info (click to toggle)
nws 2.11-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,700 kB
  • ctags: 2,820
  • sloc: ansic: 28,849; sh: 3,289; java: 1,205; makefile: 697; perl: 12
file content (191 lines) | stat: -rw-r--r-- 6,829 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#! /bin/sh
# postinst script for nws
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see /usr/doc/packaging-manual/
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

if ! test -d /var/log/nws ; then
  mkdir /var/log/nws
fi

# take care of the config file
. /usr/share/debconf/confmodule

LOCALCONF=/var/lib/nws/local.conf
mkdir -p `dirname $LOCALCONF`
rm -f $LOCALCONF

debogue() {
 :
#  [ -e $LOCALCONF ] && cp $LOCALCONF /tmp/nws.debug
}

db_get nws/debconf
if [ "$RET" = "true" ] ; then
	db_get nws/run_nameserver;		RUN_NS="$RET"
	if [ "$RET" = "false" ] ; then
		db_get nws/nameserver;		NS="$RET"
	else
		NS=`hostname`
	fi
	if expr "$NS" : '[^:]*$' > /dev/null ; then
		NS="$NS:8090"
	fi
	
	db_get nws/run_memory;			RUN_MEM="$RET"
	if [ "$RET" = "false" ] ; then
		db_get nws/memory;		MEM="$RET"
	else
		MEM=`hostname`
	fi
	if expr "$MEM" : '[^:]*$' > /dev/null ; then
		MEM="$MEM:8050"
	fi

	db_get nws/skills;			SKILLS="$RET"

echo "BEGIN" >$LOCALCONF
debogue
	cat >$LOCALCONF <<END
# ConfFile for NWS - to be parsed by nws_setup
# (generated by debian postinst script. Feel free to edit, your changes will be preserved)
  
#########################
## Syntax of this file ##
#########################
 
#  - It is read by grepping
#    That mean you can write everything you want to in it. Just, if you want a variable set
#    in the launcher, follow this syntax:
#
#                 '<no space><name of the variable>=<value>'
#
#    Every other lines are ignored, but I still mark my comments with '#'.
#  - Don't quote the values. You can't even put $name parts, and ${name} parts :)
#  - If you want a particular value to be different for a set of machines, write :
#
#        '<no space><name of the variable>(<name of the machines>)=<value>'
#
#    (name of the machine is: hostname.domainname if domainname is set.
#                             hostname            if not)
#    You can set the variable my_name, too, but only if hostname is broken, since
#     it's an internal value, too.
#
#    different machines can even share the same value. Example:
#           sensor_cpu(fulbert,toto,gabuzomeu)=yes
#
#
# Values used:
#  Here are the ones mandatory:
#   part_to_run=list of the parts of nws to run on this host
#               authorized part name are : "nameserver memory sensor forecaster"
#               order is not important. I manage this :)
#   skills=list of the skills of the server to manage

####################################
## Configuration for this machine ##
####################################

# nameserver: location of the nameserver to use
END
#EOF1;

echo "nameserver=$NS" >>$LOCALCONF 
echo                  >>$LOCALCONF
echo "# memory: location of the memory server to use" >> $LOCALCONF
echo "memory=$MEM"    >>$LOCALCONF
echo                  >>$LOCALCONF
echo "# part_to_run: nws elements to run on this machine"   >>$LOCALCONF
echo "# Possible values: nameserver memory sensor       "   >>$LOCALCONF

part_to_run=""
if [ "$RUN_NS" = "true" ] ;  then part_to_run="nameserver"           ; fi	
if [ "$RUN_MEM" = "true" ] ; then part_to_run="$part_to_run memory"  ; fi
part_to_run="$part_to_run sensor"

echo "part_to_run=$part_to_run" >> $LOCALCONF
echo                                                >>$LOCALCONF
echo "# skills: skills to activate on the sensor"   >>$LOCALCONF
echo "# possible values: cpuMonitor diskMonitor memoryMonitor tcpConnectMonitor tcpMessageMonitor"   >>$LOCALCONF


debogue
skills=""
for n in $SKILLS ; do m=`echo $n|sed 's/[, ]//g'`; skills="$skills ${m}Monitor" ; done

echo "skills=$skills"                                                      >>$LOCALCONF
echo                                                                       >>$LOCALCONF
echo "# Arguments for skill can be provided even if the skill is not used.">>$LOCALCONF
echo                                                                       >>$LOCALCONF
echo "# Arguments for the cpu skill"                                       >>$LOCALCONF
echo "skill.cpuMonitor=nice:0"                                             >>$LOCALCONF
echo                                                                       >>$LOCALCONF
echo "# Arguments for the memory skill"                                    >>$LOCALCONF
echo "skill.memoryMonitor"                                                 >>$LOCALCONF
echo                                                                       >>$LOCALCONF
echo "# Arguments for the disk skill"                                      >>$LOCALCONF
echo "skill.diskMonitor=path:/"                                            >>$LOCALCONF
echo                                                                       >>$LOCALCONF
echo "# Argument for the tcpConnect skill"                                 >>$LOCALCONF
echo "# should list all members. Should be given only on the clique leader">>$LOCALCONF

if expr "$SKILLS" : '.*tcpConnect' > /dev/null ; then
	db_get nws/tcpConnect/members
	members=""
	for m in `echo $RET` ; do members="$members member:$m "; done
else
	members="member:host1 member:host2 member:host3"
fi

echo "skill.tcpConnectMonitor=$members"                                    >>$LOCALCONF
echo                                                                       >>$LOCALCONF
echo "# Argument for the tcpMessage skill"                                 >>$LOCALCONF
echo "# should list all members. Should be given only on the clique leader">>$LOCALCONF

if expr "$SKILLS" : '.*tcpMessage' > /dev/null ; then
	db_get nws/tcpMessage/members
	members=""
	for m in `echo $RET` ; do members="$members member:$m "; done
else
	members="member:host1 member:host2 member:host3"
fi
echo "skill.tcpMessageMonitor=$members"                                    >>$LOCALCONF


db_stop
# get back stdin/stdout from debconf
exec 0<&1

debogue

rm -f $LOCALCONF.md5sum
ucf $LOCALCONF /etc/nws.conf
rm -f $LOCALCONF.md5sum


fi # only generate the conf file when asked so in debconf

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0