]> git.argeo.org Git - lgpl/argeo-commons.git/blob - dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service
[maven-release-plugin] prepare release argeo-commons-2.1.84
[lgpl/argeo-commons.git] / dist / osgi-boot / src / main / rpm / usr / sbin / osgi-service
1 #!/bin/sh
2
3 JVM=java
4 . /etc/osgiboot/osgi-service-settings.sh
5
6 APP=$1
7
8 CONF_DIR=/etc/$APP
9 if [ -f $CONF_DIR/settings.sh ];then
10 . $CONF_DIR/settings.sh
11 fi
12
13 LIB_DIR=/usr/share/$APP/lib
14
15 # read/write
16 EXEC_DIR=/var/lib/$APP
17 DATA_DIR=$EXEC_DIR/data
18 CONF_RW=$EXEC_DIR/conf
19
20 LOG_DIR=/var/log/$APP
21 LOG_FILE=$LOG_DIR/$APP.log
22
23 RUN_DIR=/var/run/$APP
24 PID_FILE=$RUN_DIR/$APP.pid
25 SHUTDOWN_FILE=$RUN_DIR/$APP.shutdown
26
27 OSGI_INSTALL_AREA=/usr/share/osgi/boot
28 OSGI_FRAMEWORK=$OSGI_INSTALL_AREA/org.eclipse.osgi.jar
29
30 RETVAL=0
31
32 start() {
33 if [ -f $PID_FILE ];then
34 PID=`cat $PID_FILE`
35 kill -0 $PID &> /dev/null
36 PID_EXISTS=$?
37 if [ $PID_EXISTS -eq 0 ]; then
38 echo $APP already running with pid $PID
39 RETVAL=1
40 return $RETVAL
41 else
42 echo Old $APP process with pid $PID is dead, removing $PID_FILE
43 rm -f $PID_FILE
44 fi
45 fi
46
47 if [ ! -f $CONF_RW/config.ini ]; then
48 #echo osgi.configuration.cascaded=true > $CONF_RW/config.ini
49 #echo osgi.sharedConfiguration.area=$CONF_DIR >> $CONF_RW/config.ini
50 #echo osgi.sharedConfiguration.area.readOnly=true >> $CONF_RW/config.ini
51 cp --preserve $CONF_DIR/config.ini $CONF_RW/config.ini
52 fi
53 touch $SHUTDOWN_FILE
54 cd $EXEC_DIR
55 $JVM \
56 -Dargeo.osgi.shutdownFile="$SHUTDOWN_FILE" \
57 -Dlog4j.configuration="file:$CONF_DIR/log4j.properties" \
58 -Djava.security.manager= \
59 -Djava.security.policy="file:/etc/osgiboot/all.policy" \
60 $JAVA_OPTS -jar $OSGI_FRAMEWORK \
61 -clean \
62 -configuration "$CONF_RW" \
63 -data "$DATA_DIR" \
64 >> $LOG_FILE 2>&1 &
65 # (above) stderr redirected to stdout, then stdout to log file
66 # see http://tldp.org/LDP/abs/html/io-redirection.html
67 PID=$!
68 echo $PID > $PID_FILE
69 #echo Started $APP with pid $PID
70 return $RETVAL
71 }
72
73 stop() {
74 if [ -f $PID_FILE ];then
75 PID=`cat $PID_FILE`
76 kill -0 $PID &> /dev/null
77 PID_EXISTS=$?
78 if [ $PID_EXISTS -ne 0 ]; then
79 echo Dead $APP process with pid $PID, removing $PID_FILE
80 rm -f $PID_FILE
81 RETVAL=1
82 return $RETVAL
83 fi
84 else
85 echo $APP is not running
86 RETVAL=1
87 return $RETVAL
88 fi
89
90 # notifies application by removing the shutdown file
91 rm -f $SHUTDOWN_FILE
92
93 # wait 5 min for application to shutdown, then kill it
94 TIMEOUT=$((5*60))
95 BEGIN=$(date +%s)
96 while kill -0 $PID &> /dev/null
97 do
98 sleep 1
99 NOW=$(date +%s)
100 DURATION=$(($NOW-$BEGIN))
101 if [ $DURATION -gt $TIMEOUT ]; then
102 kill -9 $PID
103 echo Forcibly killed $APP with pid $PID
104 RETVAL=1
105 fi
106 done
107
108 # remove pid file
109 rm -f $PID_FILE
110 return $RETVAL
111
112 # timeout is only available in EL6
113 # timeout 5m sh << EOF
114 #while kill -0 $PID &> /dev/null; do sleep 1; done
115 #EOF
116 # TIMEOUT_EXIT=$?
117 # if [ $TIMEOUT_EXIT -eq 124 ];then
118 # kill -9 $PID
119 # RETVAL=1
120 # echo Killed $APP with pid $PID
121 # else
122 # echo Stopped $APP with pid $PID
123 # fi
124 # rm -f $PID_FILE
125 # return $RETVAL
126 }
127
128 status() {
129 if [ -f $PID_FILE ];then
130 PID=`cat $PID_FILE`
131 else
132 echo $APP is not running
133 return $RETVAL
134 fi
135 kill -0 $PID &> /dev/null
136 PID_EXISTS=$?
137 if [ $PID_EXISTS -eq 0 ]; then
138 echo $APP is running with pid $PID ...
139 else
140 echo No $APP process with pid $PID, removing $PID_FILE
141 rm -f $PID_FILE
142 fi
143 return $RETVAL
144 }
145
146 # main
147 case "$2" in
148 start)
149 start
150 ;;
151 stop)
152 stop
153 ;;
154 status)
155 status
156 ;;
157 *)
158 echo $"Usage: $0 {start|stop|status}"
159 exit 1
160 esac