Saltstack Official Nginx Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RedHat-sysvinit-logger.jinja 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # /etc/init.d/nginx-logger-{{ type }}
  3. #
  4. # chkconfig: 345 84 16
  5. # description: Nginx logger for {{ type }}
  6. # processname: nginx-logger-{{ type }}
  7. NAME=nginx-logger-{{ type }}
  8. DESC="syslog forwarder for nginx {{type}} logs"
  9. DAEMON=/usr/bin/logger
  10. DAEMON_ARGS=" -f /var/log/nginx/{{ type }}.fifo -t nginx -p {% if type == 'error' %}warn{% else %}debug{% endif %}"
  11. PIDFILE=/var/run/$NAME.pid
  12. SCRIPTNAME=/etc/init.d/$NAME
  13. # Exit if the daemon program isn't installed
  14. [ -x "$DAEMON" ] || exit 0
  15. # Read configuration variable file if it is present
  16. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  17. . /etc/init.d/functions
  18. do_start() {
  19. # Return
  20. # 0 if daemon has been started
  21. # 1 if daemon was already running
  22. # 2 if daemon could not be started
  23. echo -n "Starting $NAME"
  24. pid=$(cat $PIDFILE 2>/dev/null)
  25. if [ -n "$pid" ]; then
  26. failure
  27. echo
  28. return 1;
  29. fi
  30. if [ ! -r /var/log/nginx/{{ type }}.fifo ]; then
  31. mkdir -p /var/log/nginx
  32. mkfifo /var/log/nginx/{{ type }}.fifo
  33. chown root.root /var/log/nginx/{{ type }}.fifo
  34. chmod 660 /var/log/nginx/{{ type }}.fifo
  35. fi
  36. $DAEMON $DAEMON_ARGS &
  37. ERROR=$?
  38. PID=$!
  39. if [ $ERROR -eq 0 ]; then
  40. success
  41. echo
  42. echo $PID > $PIDFILE
  43. else
  44. failure
  45. echo
  46. exit 2
  47. fi
  48. }
  49. do_stop() {
  50. # Return
  51. # 0 if daemon has been stopped
  52. # 1 if daemon was already stopped
  53. # 2 if daemon could not be stopped
  54. # other if a failure occurred
  55. echo -n Stopping $NAME
  56. pid=$(cat $PIDFILE 2>/dev/null)
  57. if [ $? -eq 0 ]; then
  58. echo $pid | xargs kill 2&1>/dev/null
  59. success
  60. RETVAL=0
  61. else
  62. failure
  63. RETVAL=1
  64. fi
  65. echo
  66. [ "$RETVAL" = 2 ] && return 2
  67. rm -f $PIDFILE
  68. return "$RETVAL"
  69. }
  70. case "$1" in
  71. start)
  72. do_start
  73. ;;
  74. stop)
  75. do_stop
  76. ;;
  77. status)
  78. status -p "$PIDFILE" "$DAEMON" && exit 0 || exit $?
  79. ;;
  80. restart|force-reload)
  81. do_stop
  82. do_start
  83. ;;
  84. *)
  85. echo "Usage: /etc/init.d/nginx-logger-{{ type }} {start|stop|status|restart|force-reload}" >&2
  86. exit 3
  87. ;;
  88. esac
  89. exit 0