onos/tools/package/init/onos.initd
Bob Lantz 3ec585d7dd Clarify config parameters/environment variables
As mentioned in the comments, ideally this script can be used as
the basis for an ONOS service in a variety of environments. Out of
the box it should work on Linux with either init.d or with systemd's
init.d compatibility. It can also be called by an upstart configuration
or a systemd configuration.

In the future we should probably remove start-stop-daemon, since that
seems to be a linux-ism. Then we could use this script on BSD, OS X,
etc..

Change-Id: I9c701c95991448fa7ddf0d84d379a4cac56cfc5f
2016-02-29 18:47:58 +00:00

62 lines
1.6 KiB
Bash
Executable File

#! /bin/bash
# -----------------------------------------------------------------------------
# init.d script to run ONOS
#
# This provides the core for an ONOS service in a variety of environments,
# including init.d, upstart, and systemd. It can also be invoked directly.
# If it is invoked by a boot system, environment variables will usually be
# empty and the default values will be used.
# -----------------------------------------------------------------------------
ONOS_HOME=${ONOS_HOME:-/opt/onos}
[ -f $ONOS_HOME/options ] && . $ONOS_HOME/options
ONOS_USER=${ONOS_USER:-root}
ONOS_GROUP=${ONOS_GROUP:-$ONOS_USER}
ONOS_OPTS=${ONOS_OPTS:-server}
ONOS_PID=${ONOS_PID:-/var/run/onos.pid}
start () {
mkdir -p $ONOS_HOME/var 2>/dev/null && chown $ONOS_USER.$ONOS_GROUP $ONOS_HOME/var
mkdir -p $ONOS_HOME/config 2>/dev/null && chown $ONOS_USER.$ONOS_GROUP $ONOS_HOME/config
[ ! -h $ONOS_HOME/log ] && ln -s $ONOS_HOME/karaf/data/log $ONOS_HOME/log || :
start-stop-daemon --signal INT --start --chuid $ONOS_USER \
--exec $ONOS_HOME/bin/onos-service --pidfile $ONOS_PID
-- $ONOS_OPTS >$ONOS_HOME/var/stdout.log 2>$ONOS_HOME/var/stderr.log
}
stop () {
$ONOS_HOME/karaf/bin/stop
}
restart () {
stop
start
}
status () {
$ONOS_HOME/karaf/bin/status
}
case $1 in
start)
start
;;
stop | force-stop)
stop
;;
restart)
shift
restart "$@"
;;
status)
status
exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0