blob: 0298c800185b7d1366eb2a517942a3916d4b877a (
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
#!/bin/sh
#
# Init script for vblade (ATA over Ethernet daemon)
#
# chkconfig: - 30 70
# description: vblade AoE daemon
#
# processname: vblade
# config: /etc/vblade.conf
#
# Shamelessly hacked together from other init scripts (sshd, mostly)
# integrate vblade.init from Fedora's vblade-14-6.fc12.src.rpm
#
RETVAL=0
prog=vblade
spawn_vblade() {
ALLOWMACS=""
[ -n "$5" ] && ALLOWMACS="-m $5"
ID="$1-e$2.$3"
if [ ! -d "/var/run/$prog" ]; then
mkdir /var/run/$prog
fi
PID_FILE=/var/run/$prog/${ID}.pid
$prog $ALLOWMACS $2 $3 $1 $4 >> /var/log/$prog.log 2>&1 &
pid=$!
RETVAL=$?
echo $pid > $PID_FILE
echo -n $"$4 (e$2.$3@$1) [pid $pid]"
[ "$RETVAL" = 0 ] && echo "success" || echo "failure"
echo
}
start() {
local ret
echo $"Starting up $prog: "
#/var/lock/subsys/$prog exists?
status $prog 2>&1 > /dev/null
ret=$?
if [ "$ret" = "2" ]; then
echo "$prog dead but subsys locked"
echo
return 2
else
if [ "$ret" = "0" ]; then
#is running
echo "already running"
return 0
fi
fi
if [ 0 -ne `grep -vc '^#\|^$' /etc/$prog.conf` ]
then
grep -v '^#' /etc/$prog.conf | sed -e 's/ / /g' -e 's/ / /g' | while read line
do
spawn_vblade $line
done
touch /var/lock/subsys/$prog
else
echo -n "empty $prog.conf?"
echo " passed"
echo
fi
}
stop() {
echo -n $"Shutting down $prog: "
for pidfile in `ls /var/run/$prog/*.pid 2>/dev/null`
do
kill -TERM `cat $pidfile`
rm -f $pidfile
done
echo "success"
echo
rm -f /var/lock/subsys/$prog
}
__pids_var_run() {
local base=${1##*/}
local pid_file=${2:-/var/run/$base.pid}
pid=
if [ -f "$pid_file" ] ; then
local line p
while : ; do
read line
[ -z "$line" ] && break
for p in $line ; do
[ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
done
done < "$pid_file"
if [ -n "$pid" ]; then
return 0
fi
return 1 # "Program is dead and /var/run pid file exists"
fi
return 3 # "Program is not running"
}
__pids_pidof() {
pidof "$1" || pidof "${1##*/}"
}
status() {
local base pid lock_file= pid_file=
# Test syntax.
if [ "$#" = 0 ] ; then
echo $"Usage: status [-p pidfile] {program}"
return 1
fi
if [ "$1" = "-p" ]; then
pid_file=$2
shift 2
fi
if [ "$1" = "-l" ]; then
lock_file=$2
shift 2
fi
base=${1##*/}
# First try "pidof"
__pids_var_run "$1" "$pid_file"
RC=$?
if [ -z "$pid_file" -a -z "$pid" ]; then
pid="$(__pids_pidof "$1")"
fi
if [ -n "$pid" ]; then
echo $"${base} (pid $pid) is running..."
return 0
fi
case "$RC" in
0)
echo $"${base} (pid $pid) is running..."
return 0
;;
1)
echo $"${base} dead but pid file exists"
return 1
;;
esac
if [ -z "${lock_file}" ]; then
lock_file=${base}
fi
# See if /var/lock/subsys/${lock_file} exists
if [ -f /var/lock/subsys/${lock_file} ]; then
echo $"${base} dead but subsys locked"
return 2
fi
echo $"${base} is stopped"
return 3
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
# yes, this sucks, but the vblade processes die on SIGHUP
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
# avoid race
sleep 3
start
fi
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
|