Improvements for init.d, upstart, and systemd-based systems
1. Change ownership of /onos/apps
onos-service needs write access to onos/apps/foo in order to activate
an app. This also means that ONOS itself could also activate/deactivate,
modify, or reinstall apps, which seems a bit dodgy but is probably
intended.
2. Fix sudo command line
The -b option was in the wrong place, breaking sudo on systems where
we use sudo to start onos (e.g. older debian or centos.)
3. Redirect stderr of 'type daemon' command
We want to detect whether the 'daemon' function/script is available
in init.d enviroments that support it, and we do so using the type
command. Previously we didn't redirect stderr, so this resulted
in a confusing error message being sent to stderr of whoever is
invoking the script.
4. onos.conf has changed to be more consistent with onos.initd
Previously onos.conf ignored $ONOS_GROUP and had a slightly different
structure.
5. onos.service has been added for systemd-based systems
This initial version of onos.service calls /etc/init.d/onos to start
and stop ONOS. In the future we may be able to call onos-service
directly, but we will need to make sure that permissions are set up
correctly so that onos-service can activate apps and so that ONOS
itself can write its log files.
6. A README has been added
7. Update the onos-install and onos-uninstall scripts
Related Jira issue: ONOS-5550
Change-Id: Ie72775f1d0a4082af9c5ea9b13999c427c15ffe0
(cherry picked from commit d22c991c6a7a8126d567d5c4a29cdf55251f6dcc)
diff --git a/tools/package/init/onos.initd b/tools/package/init/onos.initd
index 524e172..1fecfcd 100755
--- a/tools/package/init/onos.initd
+++ b/tools/package/init/onos.initd
@@ -2,10 +2,9 @@
# -----------------------------------------------------------------------------
# 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.
+# This provides the core for an ONOS service in a variety of System V/init.d
+# compatible environments. It can also be invoked directly.
+# It reads configuration options from $ONOS_HOME/options
# -----------------------------------------------------------------------------
### BEGIN INIT INFO
# Provides: onos
@@ -22,16 +21,19 @@
[ -f $ONOS_HOME/options ] && . $ONOS_HOME/options
ONOS_USER=${ONOS_USER:-root}
ONOS_GROUP=${ONOS_GROUP:-$ONOS_USER}
-ONOS_OPTS=${ONOS_OPTS:-""}
+ONOS_OPTS=${ONOS_OPTS:-server}
start () {
+ # Fix permissions and symlinks
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 || :
+ mkdir -p $ONOS_HOME/apps 2>/dev/null && chown -R $ONOS_USER:$ONOS_GROUP $ONOS_HOME/apps
+ [ ! -h $ONOS_OME/karaf ] && ln -s /opt/onos/apache-karaf* $ONOS_HOME/karaf || :
+ [ ! -h $ONOS_HOME/log ] && ln -s $ONOS_HOME/karaf/data/log $ONOS_HOME/log || :
# Start ONOS if it's not already running
if ! status >/dev/null; then
echo "Starting ONOS"
- startonos $ONOS_HOME/bin/onos-service server $ONOS_OPTS
+ startonos $ONOS_HOME/bin/onos-service $ONOS_OPTS
else
echo "ONOS/karaf is already running"
fi
@@ -47,21 +49,22 @@
. /etc/init.d/functions && true
fi
- if type daemon | grep -i function >/dev/null 2>&1; then
+ if type daemon 2>/dev/null| grep -i function >/dev/null 2>&1; then
# Use 'daemon' function if available
# Shell metacharacters are passed as arguments to daemon
daemon --user $ONOS_USER $cmd $* \
\>$ONOS_HOME/var/stdout.log 2\>$ONOS_HOME/var/stderr.log \&
elif type start-stop-daemon >/dev/null 2>&1; then
# Use start-stop-daemon if available
- # Warning! running as root can overwrite any linked log file
+ # Warning! Running as root can overwrite any linked log file.
start-stop-daemon --signal INT --start --chuid $ONOS_USER \
--background --exec $cmd -- $* \
>$ONOS_HOME/var/stdout.log 2>$ONOS_HOME/var/stderr.log
else
# Fall back to using sudo
- # Warning! running as root can overwrite any linked log file
- sudo -E -n -u -b $ONOS_USER $cmd $* \
+ # Warning! Running as root can overwrite any linked log file.
+ # preserve Env, background, non-interactive, user $ONOS_USER
+ sudo -E -b -n -u $ONOS_USER $cmd $* \
>$ONOS_HOME/var/stdout.log 2>$ONOS_HOME/var/stderr.log
fi
}
@@ -96,7 +99,7 @@
case $1 in
start)
start
- ;;
+ ;;
stop | force-stop)
stop
;;