forked from jpmens/mqtt2graphite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_server.sh
executable file
·57 lines (44 loc) · 1.39 KB
/
init_server.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
#!/bin/bash
################################################
# Get Variable
################################################
if [ "$2" != "" ]; then
MQTT_HOST=$1
CARBON_SERVER=$2
else
echo "Usage: $0 mqtt.hostname carbon.hostname '[Debug mode (True/False)]"
exit
fi
if [ "$3" != "" ]; then
DEBUG=$3
else
DEBUG=False
fi
PYTHONCMD=$(which python)
MQTT2GRAPHITECMD=$(readlink -f ./mqtt2graphite.py)
################################################
# Check if the supervisor is already initialized
################################################
if [ ! -d /etc/supervisord.d ]; then
mkdir /etc/supervisord.d
fi
if [ ! -f /etc/supervisord.conf ]; then
echo_supervisord_conf | grep -v '^;' > /etc/supervisord.conf
echo "[include]" >> /etc/supervisord.conf
echo "files = /etc/supervisord.d/*.conf" >> /etc/supervisord.conf
fi
# Configure the mqtt2graphite supervisor stater script
echo "
[program:mqtt2graphite]
command=$PYTHONCMD $MQTT2GRAPHITECMD $MQTT_HOST.conf
environment=MQTT_HOST='$1',CARBON_SERVER='$CARBON_SERVER',DEBUG=$DEBUG
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/tmp/mqtt2graphite.log
startsecs=5" > /etc/supervisord.d/mqtt2graphite.conf
# Copy the default map to the MQTT_HOST.conf
if [ ! -f $MQTT_HOST.conf ]; then
cp map $MQTT_HOST.conf
fi
echo "execute or add this cmd 'supervisord -c /etc/supervisord.conf' to your /etc/rc.local"