Committed by
Gerrit Code Review
Clarify config parameters/environment variables
As mentioned in the comments, ideally this script can be used as the basis for an ONOS service in a variety of environments. Out of the box it should work on Linux with either init.d or with systemd's init.d compatibility. It can also be called by an upstart configuration or a systemd configuration. In the future we should probably remove start-stop-daemon, since that seems to be a linux-ism. Then we could use this script on BSD, OS X, etc.. Change-Id: I9c701c95991448fa7ddf0d84d379a4cac56cfc5f
Showing
1 changed file
with
22 additions
and
19 deletions
| 1 | #! /bin/bash | 1 | #! /bin/bash |
| 2 | # ----------------------------------------------------------------------------- | 2 | # ----------------------------------------------------------------------------- |
| 3 | -# init.d script to run ONOS. | 3 | +# init.d script to run ONOS |
| 4 | +# | ||
| 5 | +# This provides the core for an ONOS service in a variety of environments, | ||
| 6 | +# including init.d, upstart, and systemd. It can also be invoked directly. | ||
| 7 | +# If it is invoked by a boot system, environment variables will usually be | ||
| 8 | +# empty and the default values will be used. | ||
| 4 | # ----------------------------------------------------------------------------- | 9 | # ----------------------------------------------------------------------------- |
| 5 | 10 | ||
| 6 | -start () { | 11 | +ONOS_HOME=${ONOS_HOME:-/opt/onos} |
| 7 | - # TODO check if ONOS is already running first | 12 | +[ -f $ONOS_HOME/options ] && . $ONOS_HOME/options |
| 8 | - | 13 | +ONOS_USER=${ONOS_USER:-root} |
| 9 | - [ -f /opt/onos/options ] && . /opt/onos/options | 14 | +ONOS_GROUP=${ONOS_GROUP:-$ONOS_USER} |
| 10 | - ONOS_USER=${ONOS_USER:-root} | 15 | +ONOS_OPTS=${ONOS_OPTS:-server} |
| 16 | +ONOS_PID=${ONOS_PID:-/var/run/onos.pid} | ||
| 11 | 17 | ||
| 12 | - # Ensure that the environment is initialized | 18 | +start () { |
| 13 | - [ -d /opt/onos ] && mkdir /opt/onos/var 2>/dev/null && chown $ONOS_USER.$ONOS_USER /opt/onos/var | 19 | + mkdir -p $ONOS_HOME/var 2>/dev/null && chown $ONOS_USER.$ONOS_GROUP $ONOS_HOME/var |
| 14 | - [ -d /opt/onos ] && mkdir /opt/onos/config 2>/dev/null && chown $ONOS_USER.$ONOS_USER /opt/onos/config | 20 | + mkdir -p $ONOS_HOME/config 2>/dev/null && chown $ONOS_USER.$ONOS_GROUP $ONOS_HOME/config |
| 15 | - [ -d /opt/onos ] && [ ! -h /opt/onos/log ] \ | 21 | + [ ! -h $ONOS_HOME/log ] && ln -s $ONOS_HOME/karaf/data/log $ONOS_HOME/log || : |
| 16 | - && ln -s /opt/onos/karaf/data/log /opt/onos/log || : | 22 | + start-stop-daemon --signal INT --start --chuid $ONOS_USER \ |
| 17 | - | 23 | + --exec $ONOS_HOME/bin/onos-service --pidfile $ONOS_PID |
| 18 | - [ -f /opt/onos/options ] && . /opt/onos/options | 24 | + -- $ONOS_OPTS >$ONOS_HOME/var/stdout.log 2>$ONOS_HOME/var/stderr.log |
| 19 | - start-stop-daemon --signal INT --start --chuid ${ONOS_USER:-root} \ | ||
| 20 | - --exec /opt/onos/bin/onos-service -- ${ONOS_OPTS:-server} \ | ||
| 21 | - >/opt/onos/var/stdout.log 2>/opt/onos/var/stderr.log | ||
| 22 | } | 25 | } |
| 23 | 26 | ||
| 24 | stop () { | 27 | stop () { |
| 25 | - /opt/onos/karaf/bin/stop | 28 | + $ONOS_HOME/karaf/bin/stop |
| 26 | } | 29 | } |
| 27 | 30 | ||
| 28 | restart () { | 31 | restart () { |
| ... | @@ -31,13 +34,13 @@ restart () { | ... | @@ -31,13 +34,13 @@ restart () { |
| 31 | } | 34 | } |
| 32 | 35 | ||
| 33 | status () { | 36 | status () { |
| 34 | - /opt/onos/karaf/bin/status | 37 | + $ONOS_HOME/karaf/bin/status |
| 35 | } | 38 | } |
| 36 | 39 | ||
| 37 | case $1 in | 40 | case $1 in |
| 38 | start) | 41 | start) |
| 39 | start | 42 | start |
| 40 | - ;; | 43 | + ;; |
| 41 | stop | force-stop) | 44 | stop | force-stop) |
| 42 | stop | 45 | stop |
| 43 | ;; | 46 | ;; | ... | ... |
-
Please register or login to post a comment