-
Notifications
You must be signed in to change notification settings - Fork 0
/
cyclades-serial-client
executable file
·177 lines (160 loc) · 3.66 KB
/
cyclades-serial-client
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
#!/usr/bin/env sh
# chkconfig: 235 55 45
# description:
# description: cyclades-serial-client script controls the interfaces of \
# the physical ports of Cyclades Terminal Servers
BASE=/etc
DEVS=${BASE}/cyclades-devices
BACKVARS=${BASE}/backvars$$
FOUND=0
BACKEXIT=0
DEV=all
GLOBALOPTS=""
export DEV DEVS FOUND BACKEXIT BACKVARS PATH
clean()
{
if [ -f ${BACKVARS} ]; then
rm -f ${BACKVARS}
fi
}
if [ $# -lt 1 -o $# -gt 2 ]; then
echo "Usage : cyclades-serial-client (start|stop|restart|status) [device]"
exit 2
fi
OPTION=$1
if [ $# -eq 2 ]; then
DEV=$2
fi
case $OPTION in
start_msg)
echo "Starting Cyclades Terminal Servers Interface"
exit 0
;;
stop_msg)
echo "Stopping Cyclades Terminal Servers Interface"
exit 0
;;
esac
if [ ! -f ${DEVS} ]; then
echo "cyclades-serial-client : device table not found"
exit 1
fi
clean
trap 'clean' 1 2 3 15
cat ${DEVS} | grep -v "#" | while read line; do
if [ -z "${line}" ]; then
continue
fi
devc=$(echo ${line} | cut -f1 -d:)
serv=$(echo ${line} | cut -f2 -d:)
host=$(echo ${line} | cut -f3 -d:)
port=$(echo ${line} | cut -f4 -d:)
type=$(echo ${line} | cut -f5 -d:)
opts=$(echo ${line} | cut -f6 -d:)
opts="$GLOBALOPTS $opts"
if [ -z "${devc}" -o -z "${serv}" -o -z "${host}" -o -z "${port}" ]; then
echo "cyclades-serial-client : Bad device table line"
BACKEXIT=3
echo "BACKEXIT=${BACKEXIT}" >> ${BACKVARS}
exit ${BACKEXIT}
fi
if [ "${DEV}" != "all" ]; then
if [ "${DEV}" != "${devc}" ]; then
continue
else
FOUND=1
echo "FOUND=${FOUND}" >> ${BACKVARS}
fi
fi
case ${type} in
rtelnet)
devst="${devc} (rtelnet at ${host}:${port})"
if [ "${serv}" = "path" ]; then
opts="-p 28672 $opts"
fi
;;
socket)
devst="${devc} ( socket at ${host}:${port})"
if [ "${serv}" = "path" ]; then
opts="-p 32768 $opts"
fi
opts="-s $opts"
;;
rfc2217)
devst="${devc} (rfc2217 at ${host}:${port})"
case ${serv} in
opengear | cm400? | cm41??)
opts="-p 5000 $opts"
;;
esac
;;
*)
echo "tsrport : Bad device table line"
BACKEXIT=2
echo "BACKEXIT=${BACKEXIT}" >> ${BACKVARS}
exit ${BACKEXIT}
;;
esac
if [ $(uname) = "Linux" ]; then
ppid=$(ps ax | grep cyclades-ser-cli | grep "${devc} " | awk '{print $1}')
else
ppid=$(ps -ef | grep cyclades-ser-cli | grep "${devc} " | awk '{print $2}')
fi
case ${OPTION} in
"start")
if [ -n "${ppid}" ]; then
echo "cyclades-serial-client : ${devc} already active"
continue
fi
echo "Starting ${devc} <<==>> ${host}:${port} interface"
cyclades-ser-cli ${opts} ${devc} ${host} ${port}
sleep 1
;;
"stop")
if [ -z "${ppid}" ]; then
echo "cyclades-serial-client : ${devc} already inactive"
continue
fi
echo "Stopping ${devc} <<==>> ${host}:${port} interface"
kill ${ppid}
;;
"restart")
if [ -z "${ppid}" ]; then
echo "cyclades-serial-client : ${devc} is inactive"
echo "Starting ${devc} <<==>> ${host}:${port} interface"
cyclades-ser-cli ${opts} ${devc} ${host} ${port}
sleep 1
else
echo \
"Restarting ${devc} <<==>> ${host}:${port} interface"
kill -s USR1 ${ppid}
fi
;;
"status")
if [ -n "${ppid}" ]; then
devst="${devst} active, pid ${ppid}"
else
devst="${devst} inactive"
fi
echo ${devst}
;;
*)
echo "Usage : cyclades-serial-client (start|stop|restart|status) [device]"
BACKEXIT=2
echo "BACKEXIT=${BACKEXIT}" >> ${BACKVARS}
exit ${BACKEXIT}
;;
esac
done
if [ -s ${BACKVARS} ]; then
. ${BACKVARS}
fi
clean
if [ ${BACKEXIT} -ne 0 ]; then
exit ${BACKEXIT}
fi
if [ "${DEV}" != "all" -a $FOUND -eq 0 ]; then
echo "cyclades-serial-client : device ${DEV} does not exist"
exit 3
fi
exit 0