init_server.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. ################################################
  3. # Get Variable
  4. ################################################
  5. if [ "$2" != "" ]; then
  6. MQTT_HOST=$1
  7. CARBON_SERVER=$2
  8. else
  9. echo "Usage: $0 mqtt.hostname carbon.hostname '[Debug mode (True/False)]"
  10. exit
  11. fi
  12. if [ "$3" != "" ]; then
  13. DEBUG=$3
  14. else
  15. DEBUG=False
  16. fi
  17. PYTHONCMD=$(which python)
  18. MQTT2GRAPHITECMD=$(readlink -f ./mqtt2graphite.py)
  19. ################################################
  20. # Check if the supervisor is already initialized
  21. ################################################
  22. if [ ! -d /etc/supervisord.d ]; then
  23. mkdir /etc/supervisord.d
  24. fi
  25. if [ ! -f /etc/supervisord.conf ]; then
  26. echo_supervisord_conf | grep -v '^;' > /etc/supervisord.conf
  27. echo "[include]" >> /etc/supervisord.conf
  28. echo "files = /etc/supervisord.d/*.conf" >> /etc/supervisord.conf
  29. fi
  30. # Configure the mqtt2graphite supervisor stater script
  31. echo "
  32. [program:mqtt2graphite]
  33. command=$PYTHONCMD $MQTT2GRAPHITECMD $MQTT_HOST.conf
  34. environment=MQTT_HOST='$1',CARBON_SERVER='$CARBON_SERVER',DEBUG=$DEBUG
  35. autostart=true
  36. autorestart=true
  37. redirect_stderr=true
  38. stdout_logfile=/tmp/mqtt2graphite.log
  39. startsecs=5" > /etc/supervisord.d/mqtt2graphite.conf
  40. # Copy the default map to the MQTT_HOST.conf
  41. if [ ! -f $MQTT_HOST.conf ]; then
  42. cp map $MQTT_HOST.conf
  43. fi
  44. echo "execute or add this cmd 'supervisord -c /etc/supervisord.conf' to your /etc/rc.local"