1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # rasdaman Startup script for the Rasdaman Server
|
---|
4 | #
|
---|
5 | # chkconfig: - 64 36
|
---|
6 | # description: Starts and stops the rasdaman server, and allows to initialize the database.
|
---|
7 | # processname: rasdaman
|
---|
8 | # config: /etc/rasdaman/rasmgr.conf
|
---|
9 | # config: /etc/sysconfig/rasdaman
|
---|
10 | # pidfile: /var/run/rasdaman.pid
|
---|
11 | #
|
---|
12 | ### BEGIN INIT INFO
|
---|
13 | # Provides: rasdaman
|
---|
14 | # Required-Start: $postgresql
|
---|
15 | # Required-Stop:
|
---|
16 | # Should-Start: distcache
|
---|
17 | # Short-Description: Starts and stops the rasdaman server, and allows to initialize the database.
|
---|
18 | # Description: The rasdaman server is a raster data manager.
|
---|
19 | ### END INIT INFO
|
---|
20 |
|
---|
21 | # Version from spec
|
---|
22 | RASVERSION=8.4.0
|
---|
23 | # RASMAJORVERSION is major version, e.g., 8.0 (this should match RAS_VERSION)
|
---|
24 | RASMAJORVERSION=`echo "$RASVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`
|
---|
25 |
|
---|
26 | # Names for messages
|
---|
27 | prog=rasdaman
|
---|
28 |
|
---|
29 | # Source function library
|
---|
30 | . /etc/rc.d/init.d/functions
|
---|
31 | # Source variables for rasdaman
|
---|
32 | if [ -f /etc/sysconfig/rasdaman ]; then
|
---|
33 | . /etc/sysconfig/rasdaman
|
---|
34 | fi
|
---|
35 |
|
---|
36 | # Reset empty to defaults
|
---|
37 | rasmgr=${RASMGR-/usr/bin/rasmgr}
|
---|
38 | rasdl=${RASMGR-/usr/bin/rasdl}
|
---|
39 | rasctrl=${RASCONTROL-/usr/bin/rascontrol}
|
---|
40 | pidfile=${PIDFILE-/var/run/rasdaman.pid}
|
---|
41 | lockfile=${LOCKFILE-/var/lock/subsys/rasdaman}
|
---|
42 | wait_for_children=${WAIT_FOR_CHILDREN-5}
|
---|
43 | servers=${RASSERVERS-"-all"}
|
---|
44 | raslogin=${RASADMIN-rasadmin:d293a15562d3e70b6fdc5ee452eaed40}
|
---|
45 | rasdir=${RASDIR-/var/lib/rasdaman}
|
---|
46 | raslogdir=${RASLOGDIR-/var/log/rasdaman}
|
---|
47 | rasshell=${RASSHELL-/bin/bash}
|
---|
48 | petapath=${PETASCOPE_PATH-/usr/share/rasdaman/petascope}
|
---|
49 |
|
---|
50 | # To check if postgres cluster was initialized
|
---|
51 | # we need this and we fetch it from our sysconfig not postgres one
|
---|
52 | PGDATA=${PGDATA-/var/lib/pgsql/data}
|
---|
53 |
|
---|
54 | RETVAL=0
|
---|
55 |
|
---|
56 | # For SELinux we need to use 'runuser' not 'su'
|
---|
57 | if [ -x /sbin/runuser ]
|
---|
58 | then
|
---|
59 | SU=runuser
|
---|
60 | else
|
---|
61 | SU=su
|
---|
62 | fi
|
---|
63 |
|
---|
64 | raslog=$rasdir/startup.log
|
---|
65 | rascontrol="RASLOGIN=$raslogin $rasctrl"
|
---|
66 | deffile=$rasdir/basictypes.dl
|
---|
67 |
|
---|
68 | # The semantics of these two functions differ from the way apachectl does
|
---|
69 | # things -- attempting to start while running is a failure, and shutdown
|
---|
70 | # when not running is also a failure. So we just do it the way init scripts
|
---|
71 | # are expected to behave here.
|
---|
72 | start() {
|
---|
73 | chown -R rasdaman:rasdaman "$raslogdir"
|
---|
74 | # Make sure startup-time log file is valid
|
---|
75 | if [ ! -e "$raslog" -a ! -h "$raslog" ]
|
---|
76 | then
|
---|
77 | touch "$raslog" || exit 1
|
---|
78 | chown rasdaman:rasdaman "$raslog"
|
---|
79 | chmod go-rwx "$raslog"
|
---|
80 | [ -x /usr/bin/chcon ] && /usr/bin/chcon -u system_u -r object_r -t postgresql_log_t "$raslog" 2>/dev/null
|
---|
81 | fi
|
---|
82 |
|
---|
83 | # Check for the PGDATA structure
|
---|
84 | if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
|
---|
85 | then
|
---|
86 | echo
|
---|
87 | echo $"PostgreSQL database was found."
|
---|
88 | echo $"Version is not checked here."
|
---|
89 | echo $"Location $PGDATA."
|
---|
90 | else
|
---|
91 | # No existing PGDATA! Warn the user to initdb it.
|
---|
92 | echo
|
---|
93 | echo "$PGDATA is missing. Use \"service rasmgr initdb\" to initialize the cluster first."
|
---|
94 | echo "PostgreSQL database will be initialized automatically."
|
---|
95 | echo_failure
|
---|
96 | echo
|
---|
97 | exit 1
|
---|
98 | fi
|
---|
99 |
|
---|
100 | echo -n $"Starting $prog: "
|
---|
101 | $SU -l rasdaman -s "$rasshell" -c "$rasmgr &" >> "$raslog" 2>&1 < /dev/null
|
---|
102 | RETVAL=$?
|
---|
103 | if [[ $RETVAL = 0 ]]
|
---|
104 | then
|
---|
105 | echo
|
---|
106 | touch ${lockfile}
|
---|
107 | pidof -s "$rasmgr" > ${pidfile}
|
---|
108 | fi
|
---|
109 |
|
---|
110 | sleep $wait_for_children
|
---|
111 |
|
---|
112 | for SRV in $servers
|
---|
113 | do
|
---|
114 | echo $"$rasctrl: starting server $SRV..."
|
---|
115 | $SU -l rasdaman -s "$rasshell" -c "$rascontrol -e -q -x up srv $SRV" >> "$raslog" 2>&1 < /dev/null
|
---|
116 | RETVAL=$?
|
---|
117 | if [[ $RETVAL != 0 ]]
|
---|
118 | then
|
---|
119 | exit $!
|
---|
120 | fi
|
---|
121 | done
|
---|
122 |
|
---|
123 | return $RETVAL
|
---|
124 | }
|
---|
125 |
|
---|
126 | # When stopping httpd a delay of >10 second is required before SIGKILLing the
|
---|
127 | # httpd parent; this gives enough time for the httpd parent to SIGKILL any
|
---|
128 | # errant children.
|
---|
129 | stop() {
|
---|
130 | running=`$SU -l rasdaman -s "$rasshell" -c "$rascontrol -e -q -x list srv | awk '{ if (\\$6 == \"UP\") print \\$2;}'"`
|
---|
131 | for SRV in $running
|
---|
132 | do
|
---|
133 | echo $"$rasctrl: stoping server $SRV..."
|
---|
134 | $SU -l rasdaman -s "$rasshell" -c "$rascontrol -e -q -x down srv $SRV -kill" >> "$raslog" 2>&1 < /dev/null
|
---|
135 | done
|
---|
136 |
|
---|
137 | sleep $wait_for_children
|
---|
138 |
|
---|
139 | $SU -l rasdaman -s "$rasshell" -c "$rascontrol -e -q -x down host -all" >> "$raslog" 2>&1 < /dev/null
|
---|
140 |
|
---|
141 | RETVAL=$?
|
---|
142 |
|
---|
143 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
|
---|
144 | }
|
---|
145 |
|
---|
146 | #
|
---|
147 | # Initializes RASBASE
|
---|
148 | #
|
---|
149 | initdb(){
|
---|
150 | bhostname=`hostname`
|
---|
151 | mv /etc/rasdaman/rasmgr.conf /etc/rasdaman/rasmgr.conf.init
|
---|
152 | cat /etc/rasdaman/rasmgr.conf.init | sed -e "s/ -host [^ ]*/ -host $bhostname/g" > /etc/rasdaman/rasmgr.conf
|
---|
153 |
|
---|
154 | service postgresql initdb
|
---|
155 | service postgresql start
|
---|
156 |
|
---|
157 | # create rasdaman user in postgres
|
---|
158 | $SU -l postgres -c "createuser -d -r -S rasdaman"
|
---|
159 | RETVAL=$?
|
---|
160 | if [[ $RETVAL != 0 ]]
|
---|
161 | then
|
---|
162 | echo $"creating rasdaman user in postgres failed"
|
---|
163 | exit $!
|
---|
164 | fi
|
---|
165 |
|
---|
166 | # create database
|
---|
167 | $SU -l rasdaman -s "$rasshell" -c "createdb RASBASE"
|
---|
168 | RETVAL=$?
|
---|
169 | if [[ $RETVAL != 0 ]]
|
---|
170 | then
|
---|
171 | echo $"creating RASBASE in postgres failed"
|
---|
172 | exit $!
|
---|
173 | fi
|
---|
174 |
|
---|
175 | # insert type definitions
|
---|
176 | $SU -l rasdaman -s "$rasshell" -c "$rasdl -c --connect RASBASE && $rasdl -r $deffile -i --connect RASBASE"
|
---|
177 | RETVAL=$?
|
---|
178 | if [[ $RETVAL != 0 ]]
|
---|
179 | then
|
---|
180 | echo $"inserting type definitions to rasdaman with rasdl failed"
|
---|
181 | exit $!
|
---|
182 | fi
|
---|
183 | }
|
---|
184 |
|
---|
185 | #
|
---|
186 | # Update RASBASE
|
---|
187 | #
|
---|
188 | updatedb()
|
---|
189 | {
|
---|
190 | $SU -l rasdaman -s "$rasshell" -c "update_db.sh"
|
---|
191 | }
|
---|
192 |
|
---|
193 | #
|
---|
194 | # Initializes/updates the petascope database
|
---|
195 | #
|
---|
196 | initpetascopedb(){
|
---|
197 | # determine tomcat user, seems to vary between different distributions
|
---|
198 | tomcat_user=`grep -i tomcat /etc/passwd | awk -F ':' '{ print $1; }' | head -n 1`
|
---|
199 | if [ -z "$tomcat_user" ]; then
|
---|
200 | tomcat_user="tomcat6"
|
---|
201 | fi
|
---|
202 |
|
---|
203 | # update petascope user in configuration, unless the user has changed it
|
---|
204 | grep 'metadata_user=tomcat6' /etc/rasdaman/petascope.properties > /dev/null
|
---|
205 | if [ $? -ne 0 ]; then
|
---|
206 | sed -i 's/^metadata_user=.\+/metadata_user='$tomcat_user'/' /etc/rasdaman/petascope.properties
|
---|
207 | fi
|
---|
208 |
|
---|
209 | # create petascope user in postgres if it isn't already created
|
---|
210 | $SU -l postgres -s "$rasshell" -c "psql -c 'SELECT * FROM pg_user'" | grep "$tomcat_user" > /dev/null
|
---|
211 | if [ $? -ne 0 ]; then
|
---|
212 | echo creating user
|
---|
213 | $SU -l postgres -c "createuser -SRd $tomcat_user"
|
---|
214 | RETVAL=$?
|
---|
215 | if [[ $RETVAL != 0 ]]
|
---|
216 | then
|
---|
217 | echo $"creating petascope user in postgres failed"
|
---|
218 | exit $!
|
---|
219 | fi
|
---|
220 | fi
|
---|
221 |
|
---|
222 | $SU -l $tomcat_user -s "$rasshell" -c "update_petascopedb.sh"
|
---|
223 | }
|
---|
224 |
|
---|
225 | #
|
---|
226 | # Drop RASBASE
|
---|
227 | #
|
---|
228 | dropdb(){
|
---|
229 | echo dropping RASBASE...
|
---|
230 | $SU -l rasdaman -s "$rasshell" -c "dropdb RASBASE"
|
---|
231 | RETVAL=$?
|
---|
232 | if [[ $RETVAL != 0 ]]
|
---|
233 | then
|
---|
234 | echo $"dropdb failed"
|
---|
235 | exit $!
|
---|
236 | fi
|
---|
237 | echo dropping user...
|
---|
238 | $SU -l postgres -s "$rasshell" -c "dropuser rasdaman"
|
---|
239 | RETVAL=$?
|
---|
240 | if [[ $RETVAL != 0 ]]
|
---|
241 | then
|
---|
242 | echo $"drop user failed"
|
---|
243 | exit $!
|
---|
244 | fi
|
---|
245 | }
|
---|
246 |
|
---|
247 | #
|
---|
248 | # Drop the petascope database
|
---|
249 | #
|
---|
250 | droppetascopedb(){
|
---|
251 | echo dropping petascopedb...
|
---|
252 | $SU -l postgres -s "$rasshell" -c "dropdb petascopedb"
|
---|
253 | RETVAL=$?
|
---|
254 | if [[ $RETVAL != 0 ]]
|
---|
255 | then
|
---|
256 | echo $"dropdb failed"
|
---|
257 | exit $!
|
---|
258 | fi
|
---|
259 | }
|
---|
260 |
|
---|
261 | # See how we were called.
|
---|
262 | case "$1" in
|
---|
263 | start)
|
---|
264 | start
|
---|
265 | ;;
|
---|
266 | stop)
|
---|
267 | stop
|
---|
268 | ;;
|
---|
269 | status)
|
---|
270 | status -p ${pidfile} $rasmgr
|
---|
271 | $SU -l rasdaman -s "$rasshell" -c "$rascontrol -e -q -x list srv"
|
---|
272 | RETVAL=$?
|
---|
273 | ;;
|
---|
274 | restart)
|
---|
275 | stop
|
---|
276 | start
|
---|
277 | ;;
|
---|
278 | condrestart)
|
---|
279 | if status -p ${pidfile} $rasmgr >&/dev/null; then
|
---|
280 | stop
|
---|
281 | start
|
---|
282 | fi
|
---|
283 | ;;
|
---|
284 | initdb)
|
---|
285 | initdb
|
---|
286 | ;;
|
---|
287 | updatedb)
|
---|
288 | updatedb
|
---|
289 | ;;
|
---|
290 | initpetascopedb)
|
---|
291 | initpetascopedb
|
---|
292 | ;;
|
---|
293 | updatepetascopedb)
|
---|
294 | initpetascopedb
|
---|
295 | ;;
|
---|
296 | dropdb)
|
---|
297 | dropdb
|
---|
298 | ;;
|
---|
299 | droppetascopedb)
|
---|
300 | droppetascopedb
|
---|
301 | ;;
|
---|
302 | *)
|
---|
303 | echo $"Usage: $prog {start|stop|restart|condrestart|status|"
|
---|
304 | echo $" initdb|updatedb|dropdb|"
|
---|
305 | echo $" initpetascopedb|updatepetascopedb|droppetascopedb}"
|
---|
306 | RETVAL=3
|
---|
307 | esac
|
---|
308 |
|
---|
309 | exit $RETVAL
|
---|