Bob Lantz
Committed by Gerrit Code Review

Fix upstart failing because of background onos-service (ONOS-4117)

1.  Invoke karaf script in all cases (upstart, initd/systemd)

This means that onos-service now blocks, which means we need to
change onos.initd to run it in the background. Otherwise, we could
use karaf/bin/start

This should fix ONOS-4117

2. Use service onos {start/status/etc.} for upstart/init/systemd

onos-install should not invoke the new init.d script directly;
instead it should use service onos {cmd, which should work if
service is available on upstart, init.d, and systemd-based
distributions.

This should fix ONOS-4124

3. In onos.initd, check if ONOS is running.

This makes it easier to see what is going on, and it also avoids
attempting to start ONOS if it's already running.

Change-Id: I0152fd7fdcb079b25531442315d0bd69e6c7653d
...@@ -48,4 +48,4 @@ for app in ${SYS_APPS//,/ } ${ONOS_APPS//,/ }; do ...@@ -48,4 +48,4 @@ for app in ${SYS_APPS//,/ } ${ONOS_APPS//,/ }; do
48 fi 48 fi
49 done 49 done
50 50
51 -exec ${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/start $KARAF_ARGS 51 +exec ${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf $KARAF_ARGS
......
...@@ -19,13 +19,22 @@ start () { ...@@ -19,13 +19,22 @@ start () {
19 mkdir -p $ONOS_HOME/var 2>/dev/null && chown $ONOS_USER.$ONOS_GROUP $ONOS_HOME/var 19 mkdir -p $ONOS_HOME/var 2>/dev/null && chown $ONOS_USER.$ONOS_GROUP $ONOS_HOME/var
20 mkdir -p $ONOS_HOME/config 2>/dev/null && chown $ONOS_USER.$ONOS_GROUP $ONOS_HOME/config 20 mkdir -p $ONOS_HOME/config 2>/dev/null && chown $ONOS_USER.$ONOS_GROUP $ONOS_HOME/config
21 [ ! -h $ONOS_HOME/log ] && ln -s $ONOS_HOME/karaf/data/log $ONOS_HOME/log || : 21 [ ! -h $ONOS_HOME/log ] && ln -s $ONOS_HOME/karaf/data/log $ONOS_HOME/log || :
22 - start-stop-daemon --signal INT --start --chuid $ONOS_USER \ 22 + # Start ONOS if it's not already running
23 - --exec $ONOS_HOME/bin/onos-service --pidfile $ONOS_PID \ 23 + if ! status > /dev/null; then
24 - -- $ONOS_OPTS >$ONOS_HOME/var/stdout.log 2>$ONOS_HOME/var/stderr.log 24 + start-stop-daemon --signal INT --start --chuid $ONOS_USER \
25 + --background --exec $ONOS_HOME/bin/onos-service \
26 + -- $ONOS_OPTS >$ONOS_HOME/var/stdout.log 2>$ONOS_HOME/var/stderr.log
27 + else
28 + echo "ONOS/karaf is already running"
29 + fi
25 } 30 }
26 31
27 stop () { 32 stop () {
28 - $ONOS_HOME/karaf/bin/stop 33 + if status> /dev/null; then
34 + $ONOS_HOME/karaf/bin/stop
35 + else
36 + echo "ONOS/karaf is not running"
37 + fi
29 } 38 }
30 39
31 restart () { 40 restart () {
...@@ -34,6 +43,7 @@ restart () { ...@@ -34,6 +43,7 @@ restart () {
34 } 43 }
35 44
36 status () { 45 status () {
46 + # karaf status returns 0 if running, 1 if not
37 $ONOS_HOME/karaf/bin/status 47 $ONOS_HOME/karaf/bin/status
38 } 48 }
39 49
......
...@@ -32,7 +32,7 @@ if [ "${1}" = "-h" -o "${1}" = "--help" ]; then ...@@ -32,7 +32,7 @@ if [ "${1}" = "-h" -o "${1}" = "--help" ]; then
32 exit 0 32 exit 0
33 fi 33 fi
34 34
35 -case $2 in 35 +case $2 in
36 start|stop|restart|status) 36 start|stop|restart|status)
37 # Select the target 37 # Select the target
38 if [ "${1}" = "--cell" ]; then 38 if [ "${1}" = "--cell" ]; then
...@@ -43,7 +43,7 @@ case $2 in ...@@ -43,7 +43,7 @@ case $2 in
43 43
44 # Execute the remote commands 44 # Execute the remote commands
45 for node in $nodes; do 45 for node in $nodes; do
46 - ssh $ONOS_USER@${node} "sudo /etc/init.d/onos ${2:-status}" 46 + ssh $ONOS_USER@${node} "sudo service onos ${2:-status}"
47 done 47 done
48 ;; 48 ;;
49 *) 49 *)
......