From a9f1ebdb3c7d4b930d09ff6c7f2e4412fd53f5d0 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 26 Sep 2012 00:15:33 +0200 Subject: initial version --- user-startup.conf | 1 + user-startup.default | 5 +++ user-startup.init | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 user-startup.conf create mode 100644 user-startup.default create mode 100755 user-startup.init diff --git a/user-startup.conf b/user-startup.conf new file mode 100644 index 0000000..8ee5338 --- /dev/null +++ b/user-startup.conf @@ -0,0 +1 @@ +# list all users, that want to start something during system startup diff --git a/user-startup.default b/user-startup.default new file mode 100644 index 0000000..d36c7f5 --- /dev/null +++ b/user-startup.default @@ -0,0 +1,5 @@ +# Default settings for user-startup. + +# During boot, let user-startup run as a daemon in the background. +# During shutdown, user-startup will always run in the foreground. +BACKGROUND_STARTUP=Yes diff --git a/user-startup.init b/user-startup.init new file mode 100755 index 0000000..1f92ba2 --- /dev/null +++ b/user-startup.init @@ -0,0 +1,95 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: user-startup +# Required-Start: $all +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Mechanism for starting/stopping user daemons +### END INIT INFO + +set -e + +PATH='/bin:/sbin:/usr/bin:/usr/sbin' + +. '/lib/lsb/init-functions' + +NAME='user-startup' +BACKGROUND_STARTUP='Yes' +CONFIG='/etc/user-startup.conf' + +test -r "${CONFIG}" || exit 0 + +if [ -r "/etc/default/$NAME" ] +then + . "/etc/default/$NAME" +fi + +case $BACKGROUND_STARTUP in +N*|n*) + BACKGROUND='0' + STARTUP_MSG='Starting user daemons' + ;; +*) + BACKGROUND='1' + STARTUP_MSG='Starting user daemons in the background' + ;; +esac + +case "$1" in +start) + log_daemon_msg "$STARTUP_MSG" "$NAME" + + grep -v '^\s*\(#\|$\)' "${CONFIG}" | while read user ; do + + USER_HOME=$(getent passwd "${user}" | cut -d: -f6) + if [ -n "${USER_HOME}" -a -d "${USER_HOME}/etc/rc.d/" ]; then + + if [ "${BACKGROUND}" = "1" ]; then + ( su - "${user}" -c "run-parts \ + --arg=start \ + --verbose \ + -- '${USER_HOME}/etc/rc.d/'" 2>&1 | logger -t user-startup ) & + else + su - "${user}" -c "run-parts \ + --arg=start \ + --verbose \ + -- '${USER_HOME}/etc/rc.d/'" 2>&1 | logger -t user-startup + fi + fi + + done + + log_end_msg $? + ;; + +stop) + log_daemon_msg 'Stopping user daemons' "$NAME" + + grep -v '^\s*\(#\|$\)' "${CONFIG}" | while read user ; do + + USER_HOME=$(getent passwd $user | cut -d: -f6) + if [ -n "${USER_HOME}" -a -d "${USER_HOME}/etc/rc.d/" ]; then + su - ${user} -c "run-parts \ + --arg=stop \ + --verbose \ + -- '${USER_HOME}/etc/rc.d/'" 2>&1 | logger -t user-startup + fi + + done + + log_end_msg $? + ;; + +restart|force-reload) + "$0" 'stop' && sleep 1 && "$0" 'start' + ;; + +*) + echo >&2 "Usage: $0 {start|stop|restart|force-reload}" + exit 3 + ;; +esac + +exit 0 -- cgit v1.2.3