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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # /etc/init.d/nginx-logger-{{ type }}
  3. #
  4. ### BEGIN INIT INFO
  5. # Provides: nginx-logger-{{ type }}
  6. # Required-Start: $local_fs $remote_fs $network $syslog
  7. # Required-Stop: $local_fs $remote_fs $network $syslog
  8. # Default-Start: 2 3 4 5
  9. # Default-Stop: 0 1 6
  10. # Short-Description: starts the nginx-logger-{{ type }}
  11. # Description: starts nginx-logger-{{ type }} using start-stop-daemon
  12. ### END INIT INFO
  13. NAME=nginx-logger-{{ type }}
  14. DESC="syslog forwarder for nginx {{type}} logs"
  15. DAEMON=/usr/bin/logger
  16. DAEMON_ARGS=" -f /var/log/nginx/{{ type }}.fifo -t nginx -p {% if type == 'error' %}warn{% else %}debug{% endif %}"
  17. PIDFILE=/var/run/$NAME.pid
  18. SCRIPTNAME=/etc/init.d/$NAME
  19. # Exit if the daemon program isn't installed
  20. [ -x "$DAEMON" ] || exit 0
  21. # Read configuration variable file if it is present
  22. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  23. . /lib/lsb/init-functions
  24. do_start() {
  25. # Return
  26. # 0 if daemon has been started
  27. # 1 if daemon was already running
  28. # 2 if daemon could not be started
  29. pid=$(pidofproc -p $PIDFILE $DAEMON)
  30. if [ -n "$pid" ]; then
  31. return 1;
  32. fi
  33. if [ ! -r /var/log/nginx/{{ type }}.fifo ]; then
  34. mkdir -p /var/log/nginx
  35. mkfifo /var/log/nginx/{{ type }}.fifo
  36. chown root.root /var/log/nginx/{{ type }}.fifo
  37. chmod 660 /var/log/nginx/{{ type }}.fifo
  38. fi
  39. start-stop-daemon --start --quiet --background --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
  40. }
  41. do_stop() {
  42. # Return
  43. # 0 if daemon has been stopped
  44. # 1 if daemon was already stopped
  45. # 2 if daemon could not be stopped
  46. # other if a failure occurred
  47. pids=$(pidof -x $DAEMON)
  48. if [ $? -eq 0 ]; then
  49. echo $pids | xargs kill 2&1>/dev/null
  50. RETVAL=0
  51. else
  52. RETVAL=1
  53. fi
  54. [ "$RETVAL" = 2 ] && return 2
  55. rm -f $PIDFILE
  56. return "$RETVAL"
  57. }
  58. case "$1" in
  59. start)
  60. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  61. do_start
  62. case "$?" in
  63. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  64. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  65. esac
  66. ;;
  67. stop)
  68. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  69. do_stop
  70. case "$?" in
  71. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  72. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  73. esac
  74. ;;
  75. status)
  76. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  77. ;;
  78. restart|force-reload)
  79. [ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME"
  80. do_stop
  81. case "$?" in
  82. 0|1)
  83. do_start
  84. case "$?" in
  85. 0) log_end_msg 0 ;;
  86. 1) log_end_msg 1 ;; # Old process still running
  87. *) log_end_msg 1 ;; # Failed to start
  88. esac
  89. ;;
  90. *)
  91. # Failed to stop
  92. log_end_msg 1
  93. ;;
  94. esac
  95. ;;
  96. *)
  97. echo "Usage: /etc/init.d/nginx-logger-{{ type }} {start|stop|status|restart|force-reload}" >&2
  98. exit 3
  99. ;;
  100. esac
  101. exit 0