UWSGI from INI
Sergei G
sergeig.public at gmail.com
Sun Feb 9 05:03:11 UTC 2014
Hi, several months ago I adjusted uwsgi script to load most of its
configuration from INI file instead of rc.conf file. It utilizes all of
uwsgi properties this way.
Do you think it is worth posting it to make available to greater audience?
I called it uwsgiini.
Here is the source code:
#!/bin/sh
#
# PROVIDE: uwsgiini
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable uwsgi:
#
# uwsgiini_enable (bool): Set it to "YES" to enable uwsgi
# Default is "NO".
#
# If you would like to have multiple uWSGI instances running, you can
# define multiple profiles:
#
# uwsgiini_profiles (str): Set the list of uwsgi profiles
# Default is "".
#
# For each profile you can then define different options (except for
# uwsgiini_enable) using the syntax uwsgi_<profile>_<option>
. /etc/rc.subr
name="uwsgiini"
rcvar=uwsgiini_enable
load_rc_config $name
command=/usr/local/bin/uwsgi
: ${uwsgiini_enable="NO"}
: ${uwsgiini_apps=""}
: ${uwsgi_pidfile="/tmp/uwsgi.pid"}
: ${uwsgi_logfile="/tmp/uwsgi.log"}
: ${uwsgi_socket="/tmp/uwsgi.sock"}
is_uwsgi_app() {
local app
for app in $uwsgiini_apps; do
if [ "$app" = "$1" ]; then
return 0
fi
done
return 1
}
if [ -n "${uwsgiini_apps}" ]; then
if [ -n "$2" ]; then
app="$2"
if ! is_uwsgi_app $app; then
echo "$app: no such app defined in uwsgiini_apps."
exit 1
fi
eval
uwsgiini_socket=\${uwsgiini_${app}_socket:-"/var/run/uwsgi-${app}/${app}.sock"}
eval
uwsgiini_pidfile=\${uwsgiini_${app}_pidfile:-"/var/run/uwsgi-${app}/${app}.pid"}
eval uwsgiini_logfile=\${uwsgiini_${app}_logfile:-"/var/log/uwsgi-${app}"}
elif [ -n "$1" ]; then
for app in ${uwsgiini_apps}; do
echo "Processing ${name} app: ${app}"
/usr/local/etc/rc.d/uwsgiini $1 ${app}
done
exit 0
fi
fi
command=/usr/local/bin/uwsgi
command_args="--ini /usr/local/etc/uwsgi.ini:${app} --daemonize
${uwsgiini_logfile} --pidfile ${uwsgiini_pidfile}"
pidfile=${uwsgiini_pidfile}
stop_postcmd=stop_postcmd
reload_precmd=reload_precmd
brutalreload_cmd=brutalreload_cmd
sig_stop="INT"
extra_commands="reload brutalreload"
procname=${uwsgiini_procname}
stop_postcmd()
{
rm -f ${uwsgiini_pidfile} # ${uwsgiini_socket}
}
reload_precmd()
{
echo "Gracefully reloading ${name} without closing the main sockets."
}
brutalreload_cmd()
{
echo "Reloading ${name} without closing the main sockets."
reload_precmd=""
sig_reload="TERM"
run_rc_command ${rc_prefix}reload $rc_extra_args || return 1
}
run_rc_command "$1"
More information about the freebsd-questions
mailing list