Saltstack Official Nginx Formula
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

114 líneas
2.7KB

  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