This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 605
Expand file tree
/
Copy pathklient.init
More file actions
120 lines (103 loc) · 2.09 KB
/
Copy pathklient.init
File metadata and controls
120 lines (103 loc) · 2.09 KB
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: klient
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Klient
# Description: Klient - Koding Service Connector
### END INIT INFO
# Klient - Koding Service Connector
# Copyright (C) 2012-2017 Koding Inc., all rights reserved.
export DEFAULT_START_COMMAND="/opt/kite/klient/klient -kontrol-url https://koding.com/kontrol/kite"
export START_COMMAND="%START_COMMAND%"
export USERNAME="%USERNAME%"
export KITE_HOME=/etc/kite
if [ -z "${START_COMMAND}" ]; then
export START_COMMAND=$DEFAULT_START_COMMAND
fi
if [ -z "${USERNAME}" ]; then
export USERNAME=root
fi
do_start() {
if is_running; then
echo "-- Koding Service Connector is already running."
return
fi
echo -n "-- Starting Koding Service Connector..."
if [ "${USERNAME}" = "root" ] && [ "$(whoami)" = "root" ]; then
nohup ${START_COMMAND} >>/var/log/klient.log 2>&1 &
else
sudo -E -u "${USERNAME}" nohup ${START_COMMAND} >>/var/log/klient.log 2>&1 &
fi
if [ ${?} -eq 0 ]; then
echo " done."
return 0
else
echo " failed!"
return 1
fi
}
do_stop() {
if is_running; then
echo -n "-- Stopping Koding Service Connector..."
if [ "${USERNAME}" = "root" ] && [ "$(whoami)" = "root" ]; then
kill $(pidof klient) >/dev/null 2>&1
else
sudo kill $(pidof klient) >/dev/null 2>&1
fi
for _ in $(seq 1 60); do
if ! is_running; then
break
fi
sleep 1
done
if is_running; then
echo " failed!"
exit 1
else
echo " done."
exit 0
fi
else
echo "-- Koding Service Connector is not running."
exit 0
fi
}
is_running() {
if [ -z "$(pidof klient)" ]; then
return 1
else
return 0
fi
}
case "$1" in
start)
# retry starting up to 3 times
for _ in $(seq 1 3); do
if do_start; then
exit 0
fi
sleep 5
done
exit 1
;;
stop)
do_stop
;;
restart)
${0} stop
${0} start
;;
status)
if is_running; then
echo "-- Koding Service Connector is running."
else
echo "-- Koding Service Connector is not running."
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
;;
esac