blob: 7a24c8d284c09582f4cd2f91700182e785a96833 (
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
|
#!/bin/bash
binary="tsclient"
arguments=""
cd "$(dirname $0)"
#export LD_LIBRARY_PATH="../wxBase-2.8.12/lib:../wxxml2/lib"
#-------------------------------------------------------------------------------
CHILDS=()
process_running()
{
CHILDS=`pgrep -d" " -x ${binary}`
if [ ! -z "${CHILDS}" ]; then
return 1
fi
return 0
}
#-------------------------------------------------------------------------------
start()
{
local retval=0
process_running
local state=$?
if [ ${state} -eq 0 ]; then
retval=1
./${binary} ${arguments}
sleep 1
process_running
state=$?
if [ ${state} -eq 1 ]; then
${OUTPUT} && echo "Process started..."
retval=1
else
${OUTPUT} && echo "Couldn't start the process"
fi
else
${OUTPUT} && echo "Process already running"
fi
return ${retval}
}
#-------------------------------------------------------------------------------
stop()
{
local retval=0
process_running
local state=$?
if [ ${state} -eq 1 ]; then
pkill -TERM -x ${binary}
sleep 1
process_running
state=$?
if [ ${state} -eq 1 ]; then
pkill -9 -x ${binary}
fi
${OUTPUT} && echo "Process stopped"
retval=1
else
${OUTPUT} && echo "Process not running"
fi
return ${retval}
}
#-------------------------------------------------------------------------------
RETVAL=0
OUTPUT=true
if [ ! -z "$2" -a "$2" = "quiet" ]; then
OUTPUT=false
fi
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart)
stop
start
RETVAL=$?
;;
status)
process_running
state=$?
if [ ${state} -eq 1 ]; then
${OUTPUT} && echo "Process is running (${CHILDS})..."
else
${OUTPUT} && echo "Process is stopped"
fi
;;
esac
exit ${RETVAL}
|