blob: 69902c6c114a6feabe6e34d8ef223439e95d93cc (
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
194
195
196
197
198
199
200
201
202
203
204
205
206
|
#! /bin/sh
# init fragment for cancd
#
# chkconfig: 2345 29 20
# description: Start cancd at system boot
#
### BEGIN INIT INFO
# Provides: cancd
# Required-Start: network
# Should-Start:
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop:
# Description: start cancd driver at system boot
### END INIT INFO
# Force LC_ALL=C
export LC_ALL=C
if [ -f /etc/redhat-release ]
then
. /etc/init.d/functions
init_status()
{
return 0
}
success_status()
{
success
echo
}
failure_status()
{
failure $1
echo
}
exit_status()
{
exit $?
}
elif [ -f /etc/SuSE-release -o -f /etc/UnitedLinux-release ]
then
. /etc/rc.status
init_status()
{
rc_reset
}
success_status()
{
/bin/true
rc_status -v
}
failure_status()
{
/bin/false
rc_status -v
}
exit_status()
{
rc_exit
}
else
init_status()
{
return 0
}
success_status()
{
echo "OK"
return 0
}
failure_status()
{
echo "Failed"
return 0
}
exit_status()
{
exit $?
}
fi
# Source configuration
[ -f /etc/sysconfig/cancd ] && . /etc/sysconfig/cancd
init_status
#
# if_fail()
#
# Evaluates return codes. If 0, prints "OK", if 1, prints "Failed"
# and exits. If 2, status is "already done" and nothing is printed.
# The rest of the functions in here all honor this convention.
#
if_fail()
{
RC="$1"
REASON="$2"
if [ "$RC" = "0" ]
then
success_status
return
elif [ "$RC" = "2" ]
then
return
fi
failure_status ${REASON}
exit 1
}
find_running()
{
ps -ef | awk '/awk/{next}/\/usr\/sbin\/cancd/{print $2}'
}
start()
{
OPT_PORT=
if [ -n "$CANCD_PORT" ]
then
OPT_PORT="-p ${CANCD_PORT}"
fi
OPT_PATH=
if [ -n "$CANCD_PATH" ]
then
OPT_PATH="-l ${CANCD_PATH}"
fi
echo -n "Starting cancd server: "
OUTPUT="`find_running 2>/dev/null`"
if [ -z "$OUTPUT" ]
then
if [ -n "$CANCD_USER" ]
then
su - "$CANCD_USER" -c "/usr/sbin/cancd $OPT_PORT $OPT_PATH"
else
/usr/sbin/cancd $OPT_PORT $OPT_PATH
fi
if_fail $? "Unable to start cancd"
else
if_fail 0 "Already running"
fi
}
stop()
{
echo -n "Stopping cancd: "
OUTPUT="`find_running 2>/dev/null`"
if [ -z "$OUTPUT" ]
then
if_fail 0 "Not running"
else
kill $OUTPUT
if_fail $? "Unable to kill cancd"
fi
}
status()
{
OUTPUT="`find_running 2>/dev/null`"
if [ -n "$OUTPUT" ]
then
echo "cancd is running"
else
echo "cancd is not running"
fi
}
case "$1" in
start)
start
;;
status)
status
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
|