Mercurial > hgrepos > FreeBSD > ports > www > uwsginl
comparison files/uwsgi.in @ 0:748e69c58ee3 origin
Added the FreeBSD port www/uwsgi as of 2017-09-13 as origin port
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Wed, 13 Sep 2017 17:09:22 +0200 |
| parents | |
| children | 9b7ee2483282 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:748e69c58ee3 |
|---|---|
| 1 #!/bin/sh | |
| 2 # | |
| 3 # $FreeBSD: head/www/uwsgi/files/uwsgi.in 448482 2017-08-21 17:49:01Z ultima $ | |
| 4 # | |
| 5 # PROVIDE: uwsgi | |
| 6 # REQUIRE: DAEMON | |
| 7 # KEYWORD: shutdown | |
| 8 # | |
| 9 # Add the following lines to /etc/rc.conf to enable uwsgi: | |
| 10 # | |
| 11 # uwsgi_enable (bool): Set it to "YES" to enable uwsgi | |
| 12 # Default is "NO". | |
| 13 # uwsgi_socket (path/str): Set the path to the uwsgi unix socket | |
| 14 # Default is /tmp/uwsgi.sock. | |
| 15 # uwsgi_socket_mode (int): Set the mode of the socket. | |
| 16 # Default is 660. | |
| 17 # uwsgi_socket_owner (str): Set the owner of the socket. | |
| 18 # Default is uwsgi:www. | |
| 19 # uwsgi_emperor (bool): Set it to "YES" to run uwsgi in emperor mode | |
| 20 # Default is "NO". | |
| 21 # uwsgi_configfile (path): Set the path to the config file | |
| 22 # Default is %%PREFIX%%/etc/uwsgi/uwsgi.ini. | |
| 23 # uwsgi_vassals_dir (path): Set the path to the vassals directory | |
| 24 # Default is %%PREFIX%%/etc/uwsgi/vassals. | |
| 25 # uwsgi_logfile (path): Set the path to the uwsgi log file | |
| 26 # Default is /var/log/uwsgi.log. | |
| 27 # uwsgi_pidfile (path): Set the path to the uwsgi pid file | |
| 28 # Default is /var/run/uwsgi.pid. | |
| 29 # uwsgi_uid (int): Set the UID of the process to run with | |
| 30 # Default is uwsgi. | |
| 31 # uwsgi_gid (int): Set the GID of the process to run with | |
| 32 # Default is uwsgi. | |
| 33 # uwsgi_flags (str): Set the uwsgi command line arguments | |
| 34 # Default is "-L". | |
| 35 # uwsgi_procname (str): Define to "uWSGI" if you start uwsgi with | |
| 36 # --auto-procname option. | |
| 37 # | |
| 38 # If you would like to have multiple uWSGI instances running, you can | |
| 39 # define multiple profiles: | |
| 40 # | |
| 41 # uwsgi_profiles (str): Set the list of uwsgi profiles | |
| 42 # Default is "". | |
| 43 # | |
| 44 # For each profile you can then define different options (except for | |
| 45 # uwsgi_enable) using the syntax uwsgi_<profile>_<option> | |
| 46 | |
| 47 . /etc/rc.subr | |
| 48 | |
| 49 name="uwsgi" | |
| 50 rcvar=uwsgi_enable | |
| 51 | |
| 52 load_rc_config $name | |
| 53 | |
| 54 command=%%PREFIX%%/bin/uwsgi | |
| 55 | |
| 56 : ${uwsgi_enable="NO"} | |
| 57 : ${uwsgi_socket="/tmp/${name}.sock"} | |
| 58 : ${uwsgi_socket_mode="660"} | |
| 59 : ${uwsgi_socket_owner="uwsgi:www"} | |
| 60 : ${uwsgi_configfile="%%PREFIX%%/etc/uwsgi/uwsgi.ini"} | |
| 61 : ${uwsgi_profiles=""} | |
| 62 : ${uwsgi_logfile="/var/log/${name}.log"} | |
| 63 : ${uwsgi_pidfile="/var/run/${name}.pid"} | |
| 64 : ${uwsgi_uid="uwsgi"} | |
| 65 : ${uwsgi_gid="uwsgi"} | |
| 66 : ${uwsgi_flags="-L"} | |
| 67 : ${uwsgi_emperor="NO"} | |
| 68 : ${uwsgi_vassals_dir="%%PREFIX%%/etc/uwsgi/vassals"} | |
| 69 | |
| 70 is_uwsgi_profile() { | |
| 71 local profile | |
| 72 | |
| 73 for profile in $uwsgi_profiles; do | |
| 74 if [ "$profile" = "$1" ]; then | |
| 75 return 0 | |
| 76 fi | |
| 77 done | |
| 78 | |
| 79 return 1 | |
| 80 } | |
| 81 | |
| 82 if [ -n "${uwsgi_profiles}" ]; then | |
| 83 if [ -n "$2" ]; then | |
| 84 profile="$2" | |
| 85 if ! is_uwsgi_profile $profile; then | |
| 86 echo "$0: no such profile defined in uwsgi_profiles." | |
| 87 exit 1 | |
| 88 fi | |
| 89 eval uwsgi_socket=\${uwsgi_${profile}_socket:-"/tmp/${name}-${profile}.sock"} | |
| 90 eval uwsgi_socket_mode=\${uwsgi_${profile}_socket_mode:-${uwsgi_socket_mode}} | |
| 91 eval uwsgi_socket_owner=\${uwsgi_${profile}_socket_owner:-${uwsgi_socket_owner}} | |
| 92 eval uwsgi_logfile=\${uwsgi_${profile}_logfile:-"/var/log/${name}-${profile}.log"} | |
| 93 eval uwsgi_pidfile=\${uwsgi_${profile}_pidfile:-"/var/run/${name}-${profile}.pid"} | |
| 94 eval uwsgi_uid=\${uwsgi_${profile}_uid:-"${uwsgi_uid}"} | |
| 95 eval uwsgi_gid=\${uwsgi_${profile}_gid:-"${uwsgi_uid}"} | |
| 96 eval uwsgi_flags=\${uwsgi_${profile}_flags:-"${uwsgi_flags}"} | |
| 97 eval uwsgi_procname=\${uwsgi_${profile}_procname:-"${uwsgi_procname}"} | |
| 98 eval uwsgi_emperor=\${uwsgi_${profile}_emperor:-"${uwsgi_emperor}"} | |
| 99 eval uwsgi_vassals_dir=\${uwsgi_${profile}_vassals_dir:-"${uwsgi_vassals_dir}"} | |
| 100 eval uwsgi_configfile=\${uwsgi_${profile}_configfile:-"${uwsgi_configfile}"} | |
| 101 elif [ -n "$1" ]; then | |
| 102 for profile in ${uwsgi_profiles}; do | |
| 103 echo "Processing ${name} profile: ${profile}" | |
| 104 %%PREFIX%%/etc/rc.d/uwsgi $1 ${profile} | |
| 105 done | |
| 106 exit 0 | |
| 107 fi | |
| 108 fi | |
| 109 | |
| 110 pidfile=${uwsgi_pidfile} | |
| 111 start_precmd=start_precmd | |
| 112 stop_postcmd=stop_postcmd | |
| 113 reload_precmd=reload_precmd | |
| 114 brutalreload_cmd=brutalreload_cmd | |
| 115 sig_stop="INT" | |
| 116 extra_commands="reload brutalreload" | |
| 117 procname=${uwsgi_procname} | |
| 118 | |
| 119 start_precmd() | |
| 120 { | |
| 121 rc_flags="" | |
| 122 if [ -e ${uwsgi_configfile} ]; then | |
| 123 rc_flags="--ini ${uwsgi_configfile} " | |
| 124 fi | |
| 125 | |
| 126 if checkyesno uwsgi_emperor; then | |
| 127 echo "Running uWSGI as Emperor. Vassals loaded from "$uwsgi_vassals_dir | |
| 128 required_dirs=${uwsgi_vassals_dir} | |
| 129 rc_flags=${rc_flags}"--emperor-pidfile ${uwsgi_pidfile} -d ${uwsgi_logfile} --emperor ${uwsgi_vassals_dir}" | |
| 130 rc_flags=${rc_flags}" --vassals-set uid=${uwsgi_uid} --vassals-set gid=${uwsgi_gid}" | |
| 131 rc_flags=${rc_flags}" --vassals-set chmod-socket=${uwsgi_socket_mode} --vassals-set chown-socket=${uwsgi_socket_owner}" | |
| 132 else | |
| 133 rc_flags=${rc_flags}"--master --uid ${uwsgi_uid} --gid ${uwsgi_gid} --pidfile ${uwsgi_pidfile} -d ${uwsgi_logfile}" | |
| 134 rc_flags=${rc_flags}" -s ${uwsgi_socket} --chmod-socket=${uwsgi_socket_mode} --chown-socket=${uwsgi_socket_owner}" | |
| 135 fi | |
| 136 | |
| 137 rc_flags=${rc_flags}" ${uwsgi_flags}" | |
| 138 } | |
| 139 | |
| 140 stop_postcmd() | |
| 141 { | |
| 142 rm -f ${uwsgi_pidfile} ${uwsgi_socket} | |
| 143 } | |
| 144 | |
| 145 reload_precmd() | |
| 146 { | |
| 147 echo "Gracefully reloading ${name} without closing the main sockets." | |
| 148 } | |
| 149 | |
| 150 brutalreload_cmd() | |
| 151 { | |
| 152 echo "Reloading ${name} without closing the main sockets." | |
| 153 | |
| 154 reload_precmd="" | |
| 155 sig_reload="TERM" | |
| 156 run_rc_command ${rc_prefix}reload $rc_extra_args || return 1 | |
| 157 } | |
| 158 | |
| 159 run_rc_command "$1" |
