blob: 05151049630caa0c4f1fd4e766c6b682b034c1ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/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 </etc/passwd
}
start_run() {
rcuser=$2
rclog="/var/log/bootrun/$rcuser.log"
touch "$rclog"
chmod 600 "$rclog"
chown "$rcuser" "$rclog"
echo "Bootrun on $(date)" >> "$rclog"
ulimit -u 500
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"
ulimit -u 500
su -l "$rcuser" -c "/usr/lib/bootrun.timeoutrun $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
|