blob: 7d67ccc69f45b17f43bf62f4ca2e2f6cbf49a41b [file] [log] [blame]
Jonathan Hartf51950d2016-01-15 09:57:10 -08001#! /bin/bash
2# -----------------------------------------------------------------------------
3# init.d script to run ONOS.
4# -----------------------------------------------------------------------------
5
6start () {
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
24stop () {
25 /opt/onos/karaf/bin/stop
26}
27
28restart () {
29 stop
30 start
31}
32
33status () {
34 /opt/onos/karaf/bin/status
35}
36
37case $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 ;;
56esac
57
58exit 0