This repository has been archived by the owner on Aug 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathgateway_initd
executable file
·126 lines (117 loc) · 2.91 KB
/
gateway_initd
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
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Gateway
# Description: Enable Gateway provided by daemon.
### END INIT INFO
dir="/opt/gateway"
user="root"
configfile="/etc/gateway.conf"
binary="/opt/gateway/bin/gateway"
name="gateway"
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.stdout.log"
stderr_log="/var/log/$name.stderr.log"
# https://github.com/WASdev/ci.chef.wlp/issues/9
if [ "$1" != "locations" ]; then
if [ "$(id -un)" != "$user" ]; then
exec su - $user -- "$0" "$@"
fi
fi
get_pid() {
cat "$pid_file"
}
is_running() {
[ -f "$pid_file" ] && ps "$(get_pid)" > /dev/null 2>&1
}
case "$1" in
start)
if [ ! -f $binary ]; then
echo "$name not installed. No such file $binary"
exit 1
fi
if [ ! -f $configfile ]; then
echo "Unable to find config file $configfile"
exit 1
fi
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir" || exit 1
if [ ! -e "$pid_file" ]; then
touch "$pid_file" > /dev/null 2> /dev/null
fi
if [ ! -w "$pid_file" ]; then
echo "Unable to start proxy: pid file $pid_file is not writable"
exit 1
fi
nohup "$binary" "-configfile" "$configfile" > "$stdout_log" 2> "$stderr_log" &
echo "$!" > "$pid_file"
sleep 1 # Give it time to try to open ports and connect
if ! is_running; then
echo "Unable to start, see $stdout_log"
exit 1
fi
echo "Started $name"
fi
;;
stop)
if is_running; then
echo "Stopping $name.."
kill "$(get_pid)"
for _ in 1 2 3 4 5 6 7 8 9 10
do
if ! is_running; then
break
fi
echo "."
sleep 1
done
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
rm -f "$pid_file"
fi
else
echo "Not running"
fi
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running on PID $(get_pid)"
else
echo "Stopped"
exit 1
fi
;;
locations)
echo "Install dir: $dir"
echo "Run as: $user"
echo "Config file: $configfile"
echo "PID file: $pid_file"
echo "Stdout log: $stdout_log"
echo "Stderr log: $stderr_log"
echo "Binary: $binary"
echo "Log directory: (Controlled by config file at $configfile)"
;;
*)
echo "Usage: $0 {start|stop|restart|status|locations}"
exit 1
;;
esac
exit 0