]> git.argeo.org Git - lgpl/argeo-commons.git/blob - osgi/dist/osgi-boot/src/main/rpm/usr/sbin/osgi-service
c1f4528127d48ab843bd4bbd88f693541e4ef469
[lgpl/argeo-commons.git] / osgi / 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/osgiboot/lib
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 cp --preserve $CONF_DIR/config.ini $CONF_RW/config.ini
48 touch $SHUTDOWN_FILE
49 cd $EXEC_DIR
50 $JVM \
51 -Dosgi.bundles="org.argeo.osgi.boot.jar@start" \
52 -Dargeo.osgi.bundles="$CONF_DIR/modules;in=*,$LIB_DIR;in=*" \
53 -Dargeo.osgi.shutdownFile="$SHUTDOWN_FILE" \
54 -Dlog4j.configuration="file:$CONF_DIR/log4j.properties" \
55 $JAVA_OPTS -jar $OSGI_FRAMEWORK \
56 -clean \
57 -configuration "$CONF_RW" \
58 -data "$DATA_DIR" \
59 &>> $LOG_FILE &
60 PID=$!
61 echo $PID > $PID_FILE
62 #echo Started $APP with pid $PID
63 return $RETVAL
64 }
65
66 stop() {
67 if [ -f $PID_FILE ];then
68 PID=`cat $PID_FILE`
69 kill -0 $PID &> /dev/null
70 PID_EXISTS=$?
71 if [ $PID_EXISTS -ne 0 ]; then
72 echo Dead $APP process with pid $PID, removing $PID_FILE
73 rm -f $PID_FILE
74 RETVAL=1
75 return $RETVAL
76 fi
77 else
78 echo $APP is not running
79 RETVAL=1
80 return $RETVAL
81 fi
82 rm -f $SHUTDOWN_FILE
83 timeout 5m sh << EOF
84 while kill -0 $PID &> /dev/null; do sleep 1; done
85 EOF
86 TIMEOUT_EXIT=$?
87 if [ $TIMEOUT_EXIT -eq 124 ];then
88 kill -9 $PID
89 RETVAL=1
90 echo Killed $APP with pid $PID
91 # else
92 # echo Stopped $APP with pid $PID
93 fi
94 rm -f $PID_FILE
95 return $RETVAL
96 }
97
98 status() {
99 if [ -f $PID_FILE ];then
100 PID=`cat $PID_FILE`
101 else
102 echo $APP is not running
103 return $RETVAL
104 fi
105 kill -0 $PID &> /dev/null
106 PID_EXISTS=$?
107 if [ $PID_EXISTS -eq 0 ]; then
108 echo $APP is running with pid $PID ...
109 else
110 echo No $APP process with pid $PID, removing $PID_FILE
111 rm -f $PID_FILE
112 fi
113 return $RETVAL
114 }
115
116 # main
117 case "$2" in
118 start)
119 start
120 ;;
121 stop)
122 stop
123 ;;
124 status)
125 status
126 ;;
127 *)
128 echo $"Usage: $0 {start|stop|status}"
129 exit 1
130 esac