Hello all,
I'm looking to deploy a Django application onto a FreeBSD 11.1 server, I've read a number of articles about using www/py36-gunicorn to provide the communications between www/nginx and Django, and brief trials appear successful.
I'm now looking to make a service that I can
Currently I have something that looks like this:
It's the beginnings of a script that is part from the Practical rc.d scripting in BSD, and part "getting it to work enough in practise". I know I need to create some variables to allow values to be read from rc.conf.
I have a few questions surrounding the subject:
Ben
I'm looking to deploy a Django application onto a FreeBSD 11.1 server, I've read a number of articles about using www/py36-gunicorn to provide the communications between www/nginx and Django, and brief trials appear successful.
I'm now looking to make a service that I can
service myapp start
, and have come up and down with the FreeBSD host.Currently I have something that looks like this:
Code:
#! /bin/sh
#
# $FreeBSD$
#
# PROVIDE: cribb
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to cribb:
#
#cribb_enable="YES"
. /etc/rc.subr
name="cribb"
rcvar="${name}_enable"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
cribb_start(){
chdir /opt/cribb
daemon -r -S -p /opt/var/run/cribb.pid -T cribb -u cribb /usr/local/bin/gunicorn-3.6 --workers 3 --bind unix:/opt/var/run/cribb.sock cribb.wsgi:application
}
cribb_stop(){
if [ -f /opt/var/run/cribb.pid ]; then
echo -n "Stopping services: ${name}"
kill -s INT $(cat /opt/var/run/cribb.pid)
if [ -f /opt/var/run/cribb.pid ]; then
rm -f /opt/var/run/cribb.pid
fi
if [ -f /opt/var/run/cribb.sock ]; then
rm -f /opt/var/run/cribb.sock
fi
echo "."
else
echo "It appears ${name} is not running."
fi
}
load_rc_config ${name}
run_rc_command "$1"
It's the beginnings of a script that is part from the Practical rc.d scripting in BSD, and part "getting it to work enough in practise". I know I need to create some variables to allow values to be read from rc.conf.
I have a few questions surrounding the subject:
- www/py36-gunicorn does not daemonise itself, is daemon(8) the correct tool to use in this case?
- I'm not sure how to stop a service running with daemon(8), so have put something together, however it doesn't look "proper" to me. Is it anywhere near correct? Or is there a better way?
- Is the whole script just awful and generally is there a better way to do this?
- Is the a better resource to read about writing service scripts? The article appears somewhat dated and limited, and there are lots of articles I've come across on the web which seem even less knowledgeable.
Ben