Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # init.d script to run ONOS. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | start () { |
| 7 | # TODO check if ONOS is already running first |
| 8 | |
| 9 | [ -f /opt/onos/options ] && . /opt/onos/options |
| 10 | ONOS_USER=${ONOS_USER:-root} |
| 11 | |
| 12 | # Ensure that the environment is initialized |
| 13 | [ -d /opt/onos ] && mkdir /opt/onos/var 2>/dev/null && chown $ONOS_USER.$ONOS_USER /opt/onos/var |
| 14 | [ -d /opt/onos ] && mkdir /opt/onos/config 2>/dev/null && chown $ONOS_USER.$ONOS_USER /opt/onos/config |
| 15 | [ -d /opt/onos ] && [ ! -h /opt/onos/log ] \ |
| 16 | && ln -s /opt/onos/karaf/data/log /opt/onos/log || : |
| 17 | |
| 18 | [ -f /opt/onos/options ] && . /opt/onos/options |
| 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 | } |
| 23 | |
| 24 | stop () { |
| 25 | /opt/onos/karaf/bin/stop |
| 26 | } |
| 27 | |
| 28 | restart () { |
| 29 | stop |
| 30 | start |
| 31 | } |
| 32 | |
| 33 | status () { |
| 34 | /opt/onos/karaf/bin/status |
| 35 | } |
| 36 | |
| 37 | case $1 in |
| 38 | start) |
| 39 | start |
| 40 | ;; |
| 41 | stop | force-stop) |
| 42 | stop |
| 43 | ;; |
| 44 | restart) |
| 45 | shift |
| 46 | restart "$@" |
| 47 | ;; |
| 48 | status) |
| 49 | status |
| 50 | exit $? |
| 51 | ;; |
| 52 | *) |
| 53 | echo "Usage: $0 {start|stop|restart|status}" >&2 |
| 54 | exit 1 |
| 55 | ;; |
| 56 | esac |
| 57 | |
| 58 | exit 0 |