]> git.argeo.org Git - lgpl/argeo-commons.git/blob - dist/argeo-node/rpm/usr/sbin/argeoctl
Add new third-parties.
[lgpl/argeo-commons.git] / dist / argeo-node / rpm / usr / sbin / argeoctl
1 #!/bin/sh
2 APP=argeo
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
17 OSGI_INSTALL_AREA=/usr/share/osgi/boot
18 OSGI_FRAMEWORK=$OSGI_INSTALL_AREA/org.eclipse.osgi.jar
19
20 # Overwrite variables
21 if [ -f $CONF_DIR/settings.sh ];then
22 . $CONF_DIR/settings.sh
23 fi
24
25 RETVAL=0
26
27 start() {
28 mkdir -p $CONF_RW
29 mkdir -p $DATA_DIR
30
31 # Merge config files
32 printf "## Equinox configuration - Generated by /usr/sbin/nodectl ##\n\n" > $CONFIG_INI
33 cat $BASE_CONFIG_INI >> $CONFIG_INI
34 printf "\n##\n## $CONF_DIR/$APP.ini\n##\n\n" >> $CONFIG_INI
35 cat $CONF_DIR/$APP.ini >> $CONFIG_INI
36 for file in `ls -v $CONF_DIRS/*.ini`; do
37 printf "\n##\n## $file\n##\n\n" >> $CONFIG_INI
38 cat $file >> $CONFIG_INI
39 done;
40
41 cd $EXEC_DIR
42 $JVM \
43 -Dlog4j.configuration="file:$CONF_DIR/log4j.properties" \
44 $JAVA_OPTS -jar $OSGI_FRAMEWORK \
45 -configuration "$CONF_RW" \
46 -data "$DATA_DIR"
47 }
48
49 reload() {
50 echo Not yet implemented
51 }
52
53 stop() {
54 if [ -f $PID_FILE ];then
55 PID=`cat $PID_FILE`
56 kill -0 $PID &> /dev/null
57 PID_EXISTS=$?
58 if [ $PID_EXISTS -ne 0 ]; then
59 echo Dead $APP process with pid $PID, removing $PID_FILE
60 rm -f $PID_FILE
61 RETVAL=1
62 return $RETVAL
63 fi
64 else
65 echo $APP is not running
66 RETVAL=1
67 return $RETVAL
68 fi
69
70 # notifies application by removing the shutdown file
71 # rm -f $SHUTDOWN_FILE
72 kill $PID
73
74 # wait 10 min for application to shutdown, then kill it
75 TIMEOUT=$((10*60))
76 BEGIN=$(date +%s)
77 while kill -0 $PID &> /dev/null
78 do
79 sleep 1
80 NOW=$(date +%s)
81 DURATION=$(($NOW-$BEGIN))
82 if [ $DURATION -gt $TIMEOUT ]; then
83 kill -9 $PID
84 echo Forcibly killed $APP with pid $PID
85 RETVAL=1
86 fi
87 done
88
89 # remove pid file
90 rm -f $PID_FILE
91 return $RETVAL
92 }
93
94 status() {
95 if [ -f $PID_FILE ];then
96 PID=`cat $PID_FILE`
97 else
98 echo $APP is not running
99 return $RETVAL
100 fi
101 kill -0 $PID &> /dev/null
102 PID_EXISTS=$?
103 if [ $PID_EXISTS -eq 0 ]; then
104 echo $APP is running with pid $PID ...
105 else
106 echo No $APP process with pid $PID, removing $PID_FILE
107 rm -f $PID_FILE
108 fi
109 return $RETVAL
110 }
111
112 # main
113 case "$1" in
114 start)
115 start
116 ;;
117 reload)
118 reload
119 ;;
120 stop)
121 stop
122 ;;
123 status)
124 status
125 ;;
126 *)
127 echo $"Usage: $0 {start|stop|status}"
128 exit 1
129 esac