blob: 5aa78d1e7f70db45c7892734c0df65ed57cd44a9 [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 || :
22 start-stop-daemon --signal INT --start --chuid $ONOS_USER \
Jonathan Hart1c401ee2016-03-01 11:46:00 -080023 --exec $ONOS_HOME/bin/onos-service --pidfile $ONOS_PID \
Bob Lantz3ec585d2016-02-25 02:54:33 -080024 -- $ONOS_OPTS >$ONOS_HOME/var/stdout.log 2>$ONOS_HOME/var/stderr.log
Jonathan Hartf51950d2016-01-15 09:57:10 -080025}
26
27stop () {
Bob Lantz3ec585d2016-02-25 02:54:33 -080028 $ONOS_HOME/karaf/bin/stop
Jonathan Hartf51950d2016-01-15 09:57:10 -080029}
30
31restart () {
32 stop
33 start
34}
35
36status () {
Bob Lantz3ec585d2016-02-25 02:54:33 -080037 $ONOS_HOME/karaf/bin/status
Jonathan Hartf51950d2016-01-15 09:57:10 -080038}
39
40case $1 in
41 start)
42 start
Bob Lantz3ec585d2016-02-25 02:54:33 -080043 ;;
Jonathan Hartf51950d2016-01-15 09:57:10 -080044 stop | force-stop)
45 stop
46 ;;
47 restart)
48 shift
49 restart "$@"
50 ;;
51 status)
52 status
53 exit $?
54 ;;
55 *)
56 echo "Usage: $0 {start|stop|restart|status}" >&2
57 exit 1
58 ;;
59esac
60
61exit 0