From c8538b8fbc96f1df22d0a21836ad55bf242fdfce Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 21 May 2011 23:37:23 +0200 Subject: initial commit Signed-off-by: Florian Pritz --- bootrun | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 bootrun (limited to 'bootrun') diff --git a/bootrun b/bootrun new file mode 100644 index 0000000..a827475 --- /dev/null +++ b/bootrun @@ -0,0 +1,67 @@ +#!/bin/bash + +get_homedirs() { + while read line; do + uname="$(cut -d: -f1 <<< "$line")" + uid="$(cut -d: -f3 <<< "$line")" + udir="$(cut -d: -f6 <<< "$line")" + if [[ "$uid" -ge 1000 ]]; then + echo "$uname:$udir" + fi + done > "$rclog" + su -l "$rcuser" -c "$1" &>> "$rclog" +} + +start() { + touch /var/log/bootrun.log + chmod 640 /var/log/bootrun.log + chown root:log /var/log/bootrun.log + mkdir -p /var/log/bootrun + + for line in $(get_homedirs); do + user="$(cut -d: -f1 <<< "$line")" + file="$(cut -d: -f2 <<< "$line")/.bootrun" + if [ -x "$file" ]; then + start_run "$file" "$user" &>> /var/log/bootrun.log + fi + done +} + +stop_run() { + rcuser=$2 + rclog="/var/log/bootrun/$rcuser.log" + touch "$rclog" + chmod 600 "$rclog" + chown "$rcuser" "$rclog" + echo "Shutdownrun on $(date)" >> "$rclog" + su -l "$rcuser" -c "/usr/lib/bootrun.timoutrun $1" &>> "$rclog" +} + +stop() { + rcpids="" + for line in $(get_homedirs); do + user="$(cut -d: -f1 <<< "$line")" + file="$(cut -d: -f2 <<< "$line")/.shutdownrun" + if [ -x "$file" ]; then + stop_run "$file" "$user" &>> /var/log/bootrun.log & + rcpids="$rcpids $!" + fi + done + + wait $rcpids +} + +case "$1" in + start) start;; + stop) stop;; + *) echo "usage: $0 {start|stop}";; +esac -- cgit v1.2.3-24-g4f1b