blob: 0323f2e969e4d3476a6d814402ed31e63ba84985 [file] [log] [blame]
Jonathan Hartf51950d2016-01-15 09:57:10 -08001#! /bin/bash
2# -----------------------------------------------------------------------------
Bob Lantz3ec585d2016-02-25 02:54:33 -08003# 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 Hartf51950d2016-01-15 09:57:10 -08009# -----------------------------------------------------------------------------
10
Bob Lantz3ec585d2016-02-25 02:54:33 -080011ONOS_HOME=${ONOS_HOME:-/opt/onos}
12[ -f $ONOS_HOME/options ] && . $ONOS_HOME/options
13ONOS_USER=${ONOS_USER:-root}
14ONOS_GROUP=${ONOS_GROUP:-$ONOS_USER}
15ONOS_OPTS=${ONOS_OPTS:-server}
16ONOS_PID=${ONOS_PID:-/var/run/onos.pid}
Jonathan Hartf51950d2016-01-15 09:57:10 -080017
Bob Lantz3ec585d2016-02-25 02:54:33 -080018start () {
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
21 [ ! -h $ONOS_HOME/log ] && ln -s $ONOS_HOME/karaf/data/log $ONOS_HOME/log || :
Bob Lantz641d5452016-03-04 19:39:17 -080022 # Start ONOS if it's not already running
23 if ! status > /dev/null; then
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
Jonathan Hartf51950d2016-01-15 09:57:10 -080030}
31
32stop () {
Bob Lantz641d5452016-03-04 19:39:17 -080033 if status> /dev/null; then
34 $ONOS_HOME/karaf/bin/stop
35 else
36 echo "ONOS/karaf is not running"
37 fi
Jonathan Hartf51950d2016-01-15 09:57:10 -080038}
39
40restart () {
41 stop
42 start
43}
44
45status () {
Bob Lantz641d5452016-03-04 19:39:17 -080046 # karaf status returns 0 if running, 1 if not
Bob Lantz3ec585d2016-02-25 02:54:33 -080047 $ONOS_HOME/karaf/bin/status
Jonathan Hartf51950d2016-01-15 09:57:10 -080048}
49
50case $1 in
51 start)
52 start
Bob Lantz3ec585d2016-02-25 02:54:33 -080053 ;;
Jonathan Hartf51950d2016-01-15 09:57:10 -080054 stop | force-stop)
55 stop
56 ;;
57 restart)
58 shift
59 restart "$@"
60 ;;
61 status)
62 status
63 exit $?
64 ;;
65 *)
66 echo "Usage: $0 {start|stop|restart|status}" >&2
67 exit 1
68 ;;
69esac
70
71exit 0