]> git.argeo.org Git - lgpl/argeo-commons.git/blob - dist/argeo-node/rpm/usr/sbin/nodectl
Replace version.argeo-distribution with version.argeo-tp
[lgpl/argeo-commons.git] / dist / argeo-node / rpm / usr / sbin / nodectl
1 #!/bin/sh
2 APP=node
3
4 JVM=java
5
6 # Directories and files
7 CONF_DIR=/etc/$APP
8 CONF_DIRS=/etc/$APP/conf.d
9 BASE_POLICY_ALL=/usr/share/$APP/all.policy
10 BASE_CONFIG_INI=/usr/share/$APP/config.ini
11
12 EXEC_DIR=/var/lib/$APP
13 DATA_DIR=$EXEC_DIR/data
14 CONF_RW=$EXEC_DIR/state
15 CONFIG_INI=$CONF_RW/config.ini
16 LOG_DIR=/var/log/$APP
17 LOG_FILE=$LOG_DIR/$APP.log
18
19 RUN_DIR=/var/run/$APP
20 PID_FILE=$RUN_DIR/$APP.pid
21
22 OSGI_INSTALL_AREA=/usr/share/osgi/boot
23 OSGI_FRAMEWORK=$OSGI_INSTALL_AREA/org.eclipse.osgi.jar
24
25 # Overwrite variables
26 if [ -f $CONF_DIR/settings.sh ];then
27 . $CONF_DIR/settings.sh
28 fi
29
30 RETVAL=0
31
32 start() {
33 mkdir -p $CONF_RW
34 mkdir -p $DATA_DIR
35 chown -R $APP.APP $EXEC_DIR
36
37 # Merge config files
38 echo ## Equinox configuration - Generated by /usr/sbin/nodectl > $CONFIG_INI
39 cat $BASE_CONFIG_INI >> $CONFIG_INI
40 cat $CONF_DIR/$APP.ini >> $CONFIG_INI
41 for file in `ls -v $CONF_DIRS/*.ini`; do
42 echo "\n# $file\n" >> $CONFIG_INI;
43 cat $file >> $CONFIG_INI
44 done;
45
46 cd $EXEC_DIR
47 $JVM \
48 -Dlog4j.configuration="file:$CONF_DIR/log4j.properties" \
49 $JAVA_OPTS -jar $OSGI_FRAMEWORK \
50 -configuration "$CONF_RW" \
51 -data "$DATA_DIR"
52 }
53
54 reload() {
55 echo Not yet implemented
56 }
57
58 stop() {
59 if [ -f $PID_FILE ];then
60 PID=`cat $PID_FILE`
61 kill -0 $PID &> /dev/null
62 PID_EXISTS=$?
63 if [ $PID_EXISTS -ne 0 ]; then
64 echo Dead $APP process with pid $PID, removing $PID_FILE
65 rm -f $PID_FILE
66 RETVAL=1
67 return $RETVAL
68 fi
69 else
70 echo $APP is not running
71 RETVAL=1
72 return $RETVAL
73 fi
74
75 # notifies application by removing the shutdown file
76 # rm -f $SHUTDOWN_FILE
77 kill $PID
78
79 # wait 10 min for application to shutdown, then kill it
80 TIMEOUT=$((10*60))
81 BEGIN=$(date +%s)
82 while kill -0 $PID &> /dev/null
83 do
84 sleep 1
85 NOW=$(date +%s)
86 DURATION=$(($NOW-$BEGIN))
87 if [ $DURATION -gt $TIMEOUT ]; then
88 kill -9 $PID
89 echo Forcibly killed $APP with pid $PID
90 RETVAL=1
91 fi
92 done
93
94 # remove pid file
95 rm -f $PID_FILE
96 return $RETVAL
97
98 # timeout is only available in EL6
99 # timeout 5m sh << EOF
100 #while kill -0 $PID &> /dev/null; do sleep 1; done
101 #EOF
102 # TIMEOUT_EXIT=$?
103 # if [ $TIMEOUT_EXIT -eq 124 ];then
104 # kill -9 $PID
105 # RETVAL=1
106 # echo Killed $APP with pid $PID
107 # else
108 # echo Stopped $APP with pid $PID
109 # fi
110 # rm -f $PID_FILE
111 # return $RETVAL
112 }
113
114 status() {
115 if [ -f $PID_FILE ];then
116 PID=`cat $PID_FILE`
117 else
118 echo $APP is not running
119 return $RETVAL
120 fi
121 kill -0 $PID &> /dev/null
122 PID_EXISTS=$?
123 if [ $PID_EXISTS -eq 0 ]; then
124 echo $APP is running with pid $PID ...
125 else
126 echo No $APP process with pid $PID, removing $PID_FILE
127 rm -f $PID_FILE
128 fi
129 return $RETVAL
130 }
131
132 # main
133 case "$1" in
134 start)
135 start
136 ;;
137 reload)
138 reload
139 ;;
140 stop)
141 stop
142 ;;
143 status)
144 status
145 ;;
146 *)
147 echo $"Usage: $0 {start|stop|status}"
148 exit 1
149 esac