-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrabbitmq-command.sh
66 lines (55 loc) · 1.19 KB
/
rabbitmq-command.sh
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
#!/bin/bash
set -e
MYID=$(id -u)
CONTROL=/usr/sbin/rabbitmqctl
#SERVER=/usr/sbin/rabbitmq-server
SERVER=/usr/lib/rabbitmq/bin/rabbitmq-server
export RABBITMQ_PID_FILE=/data/rabbitmq.pid
function die {
echo ERROR: "$@"
exit 1
}
if [ ! -x "$CONTROL" ]; then
die "can't find $CONTROL!"
fi
if [ ! -x "$SERVER" ]; then
die "can't find $SERVER!"
fi
if [ "$MYID" != "0" ]; then
die "rabbitmq startup script must be executed as root!"
fi
function remove_pid {
echo "INFO: REMOVING PIDFILE"
rm -f "$RABBITMQ_PID_FILE"
}
function stop_rabbitmq {
echo "INFO: STOPPING RABBITMQ"
if [ -f "$RABBITMQ_PID_FILE" ]; then
set +e
$CONTROL stop "$RABBITMQ_PID_FILE"
set -e
if [ $? = 0 ] ; then
remove_pid
else
echo "WARN: RABBITMQ FAILED TO STOP!"
fi
fi
}
function start_rabbitmq {
ulimit -n 1024
chown -R rabbitmq:rabbitmq /data
rm -f "$RABBITMQ_PID_FILE"
gosu rabbitmq $SERVER "$@" &
$CONTROL wait "$RABBITMQ_PID_FILE" >/dev/null 2>&1
set -e
if [ $? != 0 ] ; then
echo "ERROR: RABBITMQ FAILED TO START!"
remove_pid
fi
}
trap "stop_rabbitmq" SIGINT SIGTERM
start_rabbitmq
while [ -f "$RABBITMQ_PID_FILE" ]; do
sleep 0.25
done
echo "all done!"