SHARE
TWEET

Untitled

a guest Jun 19th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. #
  3. # PROVIDE: uwsgiini
  4. # REQUIRE: DAEMON
  5. # KEYWORD: shutdown
  6. #
  7. # Add the following lines to /etc/rc.conf to enable uwsgi:
  8. #
  9. # uwsgiini_enable (bool): Set it to "YES" to enable uwsgi
  10. # Default is "NO".
  11. #
  12. # If you would like to have multiple uWSGI instances running, you can
  13. # define multiple profiles:
  14. #
  15. # uwsgiini_profiles (str): Set the list of uwsgi profiles
  16. # Default is "".
  17. #
  18. # For each profile you can then define different options (except for
  19. # uwsgiini_enable) using the syntax uwsgi_<profile>_<option>
  20.  
  21. . /etc/rc.subr
  22.  
  23. name="uwsgiini"
  24. rcvar=uwsgiini_enable
  25.  
  26. load_rc_config $name
  27.  
  28. command=/usr/local/bin/uwsgi
  29. : ${uwsgiini_enable="NO"}
  30. : ${uwsgiini_apps=""}
  31. : ${uwsgi_socket="/tmp/${name}.sock"}
  32. : ${uwsgi_logfile="/var/log/${name}.log"}
  33. : ${uwsgi_pidfile="/var/run/${name}.pid"}
  34.  
  35. is_uwsgi_app() {
  36.     local app
  37.  
  38.     for app in $uwsgiini_apps; do
  39.         if [ "$app" = "$1" ]; then
  40.             return 0
  41.         fi
  42.     done
  43.  
  44.     return 1
  45. }
  46.  
  47. if [ -n "${uwsgiini_apps}" ]; then
  48.     if [ -n "$2" ]; then
  49.         app="$2"
  50.         if ! is_uwsgi_app $app; then
  51.         echo "$app: no such app defined in uwsgiini_apps."
  52.                 exit 1
  53.         fi
  54.         eval uwsgiini_socket=\${uwsgiini_${app}_socket:-"/var/run/uwsgi/${app}/${app}.sock"}
  55.         eval uwsgiini_pidfile=\${uwsgiini_${app}_pidfile:-"/var/run/uwsgi/${app}/${app}.pid"}
  56.         eval uwsgiini_logfile=\${uwsgiini_${app}_logfile:-"/var/log/uwsgi/${app}.log"}
  57.     elif [ -n "$1" ]; then
  58.         for app in ${uwsgiini_apps}; do
  59.                     echo "Processing ${name} app: ${app}"
  60.                     /usr/local/etc/rc.d/uwsgiini $1 ${app}
  61.                 done
  62.                 exit 0
  63.     fi
  64. fi
  65.  
  66. command=/usr/local/bin/uwsgi
  67. command_args="--ini /usr/local/etc/uwsgi.ini:${app} --daemonize ${uwsgiini_logfile} --pidfile ${uwsgiini_pidfile}"
  68. pidfile=${uwsgiini_pidfile}
  69. stop_postcmd=stop_postcmd
  70. reload_precmd=reload_precmd
  71. brutalreload_cmd=brutalreload_cmd
  72. sig_stop="INT"
  73. extra_commands="reload brutalreload"
  74. procname=${uwsgiini_procname}
  75.  
  76. stop_postcmd()
  77. {
  78.     rm -f ${uwsgiini_pidfile} # ${uwsgiini_socket}
  79. }
  80.  
  81. reload_precmd()
  82. {
  83.     echo "Gracefully reloading ${name} without closing the main sockets."
  84. }
  85.  
  86. brutalreload_cmd()
  87. {
  88.     echo "Reloading ${name} without closing the main sockets."
  89.  
  90.     reload_precmd=""
  91.     sig_reload="TERM"
  92.     run_rc_command ${rc_prefix}reload $rc_extra_args || return 1
  93. }
  94.  
  95. run_rc_command "$1"
RAW Paste Data
Top