Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
Bob Lantz | 3ec585d | 2016-02-25 02:54:33 -0800 | [diff] [blame] | 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. |
Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 9 | # ----------------------------------------------------------------------------- |
Jonathan Hart | e01652f | 2016-03-29 10:25:11 -0700 | [diff] [blame] | 10 | ### BEGIN INIT INFO |
| 11 | # Provides: onos |
| 12 | # Required-Start: $network $remote_fs $syslog |
| 13 | # Required-Stop: $network $remote_fs $syslog |
| 14 | # Default-Start: 2 3 4 5 |
| 15 | # Default-Stop: 0 1 6 |
| 16 | # Short-Description: ONOS network operating system |
| 17 | # Description: ONOS is a network operating system for controlling SDN networks, designed for high availablility, performance, and scale out. |
| 18 | ### END INIT INFO |
| 19 | |
Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 20 | |
Bob Lantz | 3ec585d | 2016-02-25 02:54:33 -0800 | [diff] [blame] | 21 | ONOS_HOME=${ONOS_HOME:-/opt/onos} |
| 22 | [ -f $ONOS_HOME/options ] && . $ONOS_HOME/options |
| 23 | ONOS_USER=${ONOS_USER:-root} |
| 24 | ONOS_GROUP=${ONOS_GROUP:-$ONOS_USER} |
| 25 | ONOS_OPTS=${ONOS_OPTS:-server} |
| 26 | ONOS_PID=${ONOS_PID:-/var/run/onos.pid} |
Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 27 | |
Bob Lantz | 3ec585d | 2016-02-25 02:54:33 -0800 | [diff] [blame] | 28 | start () { |
| 29 | mkdir -p $ONOS_HOME/var 2>/dev/null && chown $ONOS_USER.$ONOS_GROUP $ONOS_HOME/var |
| 30 | mkdir -p $ONOS_HOME/config 2>/dev/null && chown $ONOS_USER.$ONOS_GROUP $ONOS_HOME/config |
| 31 | [ ! -h $ONOS_HOME/log ] && ln -s $ONOS_HOME/karaf/data/log $ONOS_HOME/log || : |
Bob Lantz | 641d545 | 2016-03-04 19:39:17 -0800 | [diff] [blame] | 32 | # Start ONOS if it's not already running |
| 33 | if ! status > /dev/null; then |
| 34 | start-stop-daemon --signal INT --start --chuid $ONOS_USER \ |
| 35 | --background --exec $ONOS_HOME/bin/onos-service \ |
| 36 | -- $ONOS_OPTS >$ONOS_HOME/var/stdout.log 2>$ONOS_HOME/var/stderr.log |
| 37 | else |
| 38 | echo "ONOS/karaf is already running" |
| 39 | fi |
Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | stop () { |
Bob Lantz | 641d545 | 2016-03-04 19:39:17 -0800 | [diff] [blame] | 43 | if status> /dev/null; then |
| 44 | $ONOS_HOME/karaf/bin/stop |
| 45 | else |
| 46 | echo "ONOS/karaf is not running" |
| 47 | fi |
Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | restart () { |
| 51 | stop |
| 52 | start |
| 53 | } |
| 54 | |
| 55 | status () { |
Bob Lantz | 641d545 | 2016-03-04 19:39:17 -0800 | [diff] [blame] | 56 | # karaf status returns 0 if running, 1 if not |
Bob Lantz | 3ec585d | 2016-02-25 02:54:33 -0800 | [diff] [blame] | 57 | $ONOS_HOME/karaf/bin/status |
Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | case $1 in |
| 61 | start) |
| 62 | start |
Bob Lantz | 3ec585d | 2016-02-25 02:54:33 -0800 | [diff] [blame] | 63 | ;; |
Jonathan Hart | f51950d | 2016-01-15 09:57:10 -0800 | [diff] [blame] | 64 | stop | force-stop) |
| 65 | stop |
| 66 | ;; |
| 67 | restart) |
| 68 | shift |
| 69 | restart "$@" |
| 70 | ;; |
| 71 | status) |
| 72 | status |
| 73 | exit $? |
| 74 | ;; |
| 75 | *) |
| 76 | echo "Usage: $0 {start|stop|restart|status}" >&2 |
| 77 | exit 1 |
| 78 | ;; |
| 79 | esac |
| 80 | |
| 81 | exit 0 |