blob: bd0a7969727567387d88b15ec862a6b93ece9ff1 (
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
|
#!/bin/sh /etc/rc.common
START=73
BIN=luaclient
DAEMON=/usr/bin/$BIN
DESC=$BIN
RUN_D=/var/run/rhctl
option_cb() {
local varname="$1"
local value="$2"
if ! echo "$CONFIG_OPTIONS" | grep " $varname " > /dev/null; then
CONFIG_OPTIONS="$CONFIG_OPTIONS $varname "
fi
}
foreach_config_forced() {
foreach_config $1 "$2" "forced"
}
foreach_config() {
local cfg="$1"
local name
local option
local value
local args=""
local forced=0
config_get name "$cfg" "name"
if [ -n "$2" ] && [ "x$2" != "x$name" ]; then
return
fi
if [ -n "$3" ] && [ "x$3" == "xforced" ]; then
forced=1
fi
for option in $CONFIG_OPTIONS
do
config_get value "$cfg" "$option"
if [ "x$option" == "xdisabled" ]; then
if [ $forced -eq 0 ] && [ -n "$value" ] && [ $value -eq 1 ]; then
echo -n " $name(disabled)"
return
fi
continue
fi
if [ "x$option" == "xname" ]; then
continue
fi
option=`echo $option | tr '_' '-'`
if [ -n "$value" ]; then
args="$args --$option $value"
fi
done
echo -n " $name"
local status="OK"
$DAEMON --write-pid "$RUN_D/$BIN.$name.pid" $args || status="failed"
echo -n "($status)"
}
stop_client() {
local name=$1
local pidfile=$RUN_D/$BIN.$name.pid
echo -n " $name"
local status="OK"
if [ ! -f "$pidfile" ]; then
status="tunnel not active"
else
kill `cat $pidfile` > /dev/null 2>&1 || status="failed"
rm -f $pidfile
fi
echo -n "($status)"
}
start() {
echo -n "Starting $DESC:"
config_load "rhctl"
if [ $# -gt 0 ]; then
while [ $# -gt 0 ]; do
config_foreach foreach_config_forced "luaclient" "$1"
shift
done
else
config_foreach foreach_config "luaclient"
fi
echo "."
}
stop() {
echo -n "Stopping $DESC:"
local name
local pidfile
if [ $# -gt 0 ]; then
while [ $# -gt 0 ]; do
stop_client $1
shift
done
else
for pidfile in `ls $RUN_D/$BIN.*.pid 2> /dev/null`; do
name=${pidfile%%.pid}
name=${name##$RUN_D/$BIN.}
stop_client $name
done
fi
echo "."
}
|