summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-09-26 00:15:33 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2012-09-26 00:30:17 +0200
commita9f1ebdb3c7d4b930d09ff6c7f2e4412fd53f5d0 (patch)
tree2c7dca07def322ce3636a0558b863e3a61a27112
downloaduser-startup-a9f1ebdb3c7d4b930d09ff6c7f2e4412fd53f5d0.tar.gz
user-startup-a9f1ebdb3c7d4b930d09ff6c7f2e4412fd53f5d0.tar.xz
user-startup-a9f1ebdb3c7d4b930d09ff6c7f2e4412fd53f5d0.zip
initial version
Diffstat (limited to '')
-rw-r--r--user-startup.conf1
-rw-r--r--user-startup.default5
-rwxr-xr-xuser-startup.init95
3 files changed, 101 insertions, 0 deletions
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