Saltstack Official Nginx Formula
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

104 lines
2.3KB

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