This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 938
/
orchestrator.bash
134 lines (124 loc) · 3.6 KB
/
orchestrator.bash
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
#!/bin/bash
# orchestrator daemon
# chkconfig: 345 20 80
# description: orchestrator daemon
# processname: orchestrator
#
### BEGIN INIT INFO
# Provides: orchestrator
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start orchestrator daemon
# Description: Start orchestrator daemon
### END INIT INFO
# Script credit: http://werxltd.com/wp/2012/01/05/simple-init-d-script-template/
DAEMON_PATH="/usr/local/orchestrator"
DAEMON=orchestrator
DAEMONOPTS="--verbose http"
NAME=orchestrator
DESC="orchestrator: MySQL replication management and visualization"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Limit the number of file descriptors (and sockets) used by
# orchestrator. This setting should be fine in most cases but a
# large busy environment may # reach this limit. If exceeded expect
# to see errors of the form:
# 2017-06-12 02:33:09 ERROR dial tcp 10.1.2.3:3306: connect: cannot assign requested address
# To avoid touching this script you can use /etc/orchestrator_profile
# to increase this limit.
ulimit -n 16384
# initially noop but can adjust according by modifying orchestrator_profile
# - see https://github.com/openark/orchestrator/issues/227 for more details.
post_start_daemon_hook () {
# by default do nothing
:
}
# Start the orchestrator daemon in the background
start_daemon () {
# start up daemon in the background
$DAEMON_PATH/$DAEMON $DAEMONOPTS >> /var/log/${NAME}.log 2>&1 &
# collect and print PID of started process
echo $!
# space for optional processing after starting orchestrator
# - redirect stdout to stderro to prevent this corrupting the pid info
post_start_daemon_hook 1>&2
}
# This files can be used to inject pre-service execution
# scripts, such as exporting variables or whatever. It's yours!
[ -f /etc/default/orchestrator ] && . /etc/default/orchestrator
[ -f /etc/orchestrator_profile ] && . /etc/orchestrator_profile
[ -f /etc/profile.d/orchestrator ] && . /etc/profile.d/orchestrator
case "$1" in
start)
printf "%-50s" "Starting $NAME..."
cd $DAEMON_PATH
PID=$(start_daemon)
#echo "Saving PID" $PID " to " $PIDFILE
if [ -z $PID ]; then
printf "%s\n" "Fail"
exit 1
elif [ -z "$(ps axf | awk '{print $1}' | grep ${PID})" ]; then
printf "%s\n" "Fail"
exit 1
else
echo $PID > $PIDFILE
printf "%s\n" "Ok"
fi
;;
status)
printf "%-50s" "Checking $NAME..."
if [ -f $PIDFILE ]; then
PID=$(cat $PIDFILE)
if [ -z "$(ps axf | awk '{print $1}' | grep ${PID})" ]; then
printf "%s\n" "Process dead but pidfile exists"
exit 1
else
echo "Running"
fi
else
printf "%s\n" "Service not running"
exit 1
fi
;;
stop)
printf "%-50s" "Stopping $NAME"
PID=$(cat $PIDFILE)
cd $DAEMON_PATH
if [ -f $PIDFILE ]; then
kill -TERM $PID
rm -f $PIDFILE
# Wait for orchestrator to stop otherwise restart may fail.
# (The newly restarted process may be unable to bind to the
# currently bound socket.)
while ps -p $PID >/dev/null 2>&1; do
printf "."
sleep 1
done
printf "\n"
printf "Ok\n"
else
printf "%s\n" "pidfile not found"
exit 1
fi
;;
restart)
$0 stop
$0 start
;;
reload)
PID=$(cat $PIDFILE)
cd $DAEMON_PATH
if [ -f $PIDFILE ]; then
kill -HUP $PID
printf "%s\n" "Ok"
else
printf "%s\n" "pidfile not found"
exit 1
fi
;;
*)
echo "Usage: $0 {status|start|stop|restart|reload}"
exit 1
esac