uwsgi 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: uwsgi
  4. # Required-Start: $local_fs $remote_fs $network
  5. # Required-Stop: $local_fs $remote_fs $network
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Start/stop uWSGI server instance(s)
  9. # Description: This script manages uWSGI server instance(s).
  10. # You could control specific instance(s) by issuing:
  11. #
  12. # service uwsgi <command> <confname> <confname> ...
  13. #
  14. # You can issue to init.d script following commands:
  15. # * start | starts daemon
  16. # * stop | stops daemon
  17. # * reload | sends to daemon SIGHUP signal
  18. # * force-reload | sends to daemon SIGTERM signal
  19. # * restart | issues 'stop', then 'start' commands
  20. # * status | shows status of daemon instance
  21. #
  22. # 'status' command must be issued with exactly one
  23. # argument: '<confname>'.
  24. #
  25. # In init.d script output:
  26. # * . -- command was executed without problems or instance
  27. # is already in needed state
  28. # * ! -- command failed (or executed with some problems)
  29. # * ? -- configuration file for this instance isn't found
  30. # and this instance is ignored
  31. #
  32. # For more details see /usr/share/doc/uwsgi/README.Debian.
  33. ### END INIT INFO
  34. # Author: Leonid Borisenko <[email protected]>
  35. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  36. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  37. DESC="app server(s)"
  38. NAME="uwsgi"
  39. DAEMON="/usr/bin/uwsgi"
  40. SCRIPTNAME="/etc/init.d/${NAME}"
  41. UWSGI_CONFDIR="/etc/uwsgi"
  42. UWSGI_APPS_CONFDIR_SUFFIX="s-enabled"
  43. UWSGI_APPS_CONFDIR_GLOB="${UWSGI_CONFDIR}/app${UWSGI_APPS_CONFDIR_SUFFIX}"
  44. UWSGI_RUNDIR="/run/uwsgi"
  45. # Configuration namespace is used as name of runtime and log subdirectory.
  46. # uWSGI instances sharing the same app configuration directory also shares
  47. # the same runtime and log subdirectory.
  48. #
  49. # When init.d script cannot detect namespace for configuration file, default
  50. # namespace will be used.
  51. UWSGI_DEFAULT_CONFNAMESPACE=app
  52. # Exit if the package is not installed
  53. [ -x "$DAEMON" ] || exit 0
  54. # Load the VERBOSE setting and other rcS variables
  55. . /lib/init/vars.sh
  56. # Read configuration variable file if it is present
  57. [ -r "/etc/default/${NAME}" ] && . "/etc/default/${NAME}"
  58. # Define LSB log_* functions.
  59. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  60. . /lib/lsb/init-functions
  61. # Define supplementary functions
  62. . /usr/share/uwsgi/init/snippets
  63. . /usr/share/uwsgi/init/do_command
  64. WHAT=$1
  65. shift
  66. case "$WHAT" in
  67. start)
  68. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  69. do_command "$WHAT" "$@"
  70. RETVAL="$?"
  71. RETVAL=0
  72. [ "$VERBOSE" != no ] && log_end_msg "$RETVAL"
  73. ;;
  74. stop)
  75. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  76. do_command "$WHAT" "$@"
  77. RETVAL="$?"
  78. [ "$VERBOSE" != no ] && log_end_msg "$RETVAL"
  79. ;;
  80. status)
  81. if [ -z "$1" ]; then
  82. [ "$VERBOSE" != no ] && log_failure_msg "which one?"
  83. else
  84. PIDFILE="$(
  85. find_specific_pidfile "$(relative_path_to_conffile_with_spec "$1")"
  86. )"
  87. status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" \
  88. && exit 0 \
  89. || exit $?
  90. fi
  91. ;;
  92. reload)
  93. [ "$VERBOSE" != no ] && log_daemon_msg "Reloading $DESC" "$NAME"
  94. do_command "$WHAT" "$@"
  95. RETVAL="$?"
  96. [ "$VERBOSE" != no ] && log_end_msg "$RETVAL"
  97. ;;
  98. force-reload)
  99. [ "$VERBOSE" != no ] && log_daemon_msg "Forced reloading $DESC" "$NAME"
  100. do_command "$WHAT" "$@"
  101. RETVAL="$?"
  102. [ "$VERBOSE" != no ] && log_end_msg "$RETVAL"
  103. ;;
  104. restart)
  105. [ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME"
  106. CURRENT_VERBOSE=$VERBOSE
  107. VERBOSE=no
  108. do_command stop "$@"
  109. VERBOSE=$CURRENT_VERBOSE
  110. case "$?" in
  111. 0)
  112. do_command start "$@"
  113. RETVAL="$?"
  114. [ "$VERBOSE" != no ] && log_end_msg "$RETVAL"
  115. ;;
  116. *)
  117. # Failed to stop
  118. [ "$VERBOSE" != no ] && log_end_msg 1
  119. ;;
  120. esac
  121. ;;
  122. *)
  123. echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
  124. exit 3
  125. ;;
  126. esac