Trying to set up simple service to run django development server

Code:
#!/bin/sh
. /etc/rc.subr

name="dashboard"
rcvar="${name}_enable"
load_rc_config ${name}

: ${dashboard_enable:=NO}
: ${dashboard_user:=root}
: ${dashboard_group:=wheel}
: ${dashboard_pidfile:="/var/run/${name}/${name}.pid"}

start_precmd=". /zroot/www/venv/bin/activate"
pidfile=${dashboard_pidfile}
command_interpreter="/zroot/www/venv/bin/python"
command="/zroot/www/dashboard/manage.py"
command_args="runserver 0.0.0.0:8012"                                                                                               1
run_rc_command "$1"
It doesn't write to the pid file. Am I supposed to manually create the file before hand?

It doesn't see that it's running when I check the status, probably because of the pidfile issue.

It also won't start at boot, probably due to the same issue.

What am I missing here?
 
Sorry bud. I just set it up temporarily that way to try to get things working.

Believe me, I'm stressing out too, for a whole different reason.
 
Depends on the service. Services that always run will usually be started and stopped at boot/shutdown, these only need <service name>_enabled="YES" in /etc/rc.conf. Since the pid-file is missing Django probably isn't started at all. I don't know Django well enough to tell what is needed for it to run, you know better than me. You found the right guide already, you might want to take a look at the files in /usr/local/etc/rc.d for an example. That is where your rc file should reside, because Django is not part of the base system. You'll find files for apache, dbus, cupsd, saned and the likes there. Take a look at those, some are very short and simple.
 
Well I can start the service manually. It just doesn't start at boot even though it is enabled. Yes the file is located in /usr/local/etc/rc.d

But even when I start the service, nothing happens to the pid file. If it doesn't exist, it is not created. If I manually create it beforehand, it is not written to. But the service works and I can access the dashboard page from a browser. Also checking the status will say the service is not running, even though it is. It just seems like the pidfile variable isn't working. I have seen other people say you have to set the procname variable to get it to work but I tried setting it to the same python path in the command_interpreter variable and that didn't change anything.

I'm just guessing, but I think once I can get pidfile working then maybe it will start at boot, as expected.
 
I don't see an option for writing a pid file in the runserver documentation:

Contrast with the WSGI docs which do have a pid file option:

I can't prove this, but I think you'll need a start_cmd and stop_cmd if the program you're trying to daemonize does not create a pid file.
 
thedude22 said:
I think once I can get pidfile working then maybe it will start at boot, as expected

Start at boot and write a pid file are different things. A binary may or may not write a .pid. Django obviously doesn't because it's not there when you run it. I wrote a simple daemon in Perl that logs incoming phone calls. This is the file (/usr/local/etc/rc.d/fbcalls) that I use to start at boot and stop at shutdown:
Code:
#!/bin/sh

echo -n " fbcalls "

case $1 in
start)
   echo -n "starting.."
   /usr/local/sbin/fbcalls.pl -o
   ;;
stop)
   echo -n "stopping..."
   kill -s TERM `cat /var/run/fbcalls.pid`
   ;;
*)
   echo "usage $0: [ start | stop ]" 2>&1
   ;;
esac

It starts at boot saying "fbcalls starting...", you can see why. It will stop at shutdown. Perl script fbcalls.pl writes the .pid file, so it can be used to kill that process at shutdown. Now Django doesn't write a .pid, so we have to do it ourselves. In this example that could be done by adding a line pgrep -f fbcalls > /var/run/fbcalls.pid immediately after starting the perl script.
 
Thanks for the suggestions. I think I'll just set up a proper web server. I was trying to avoid it because it's just a page for only one user, me, and on my LAN only. But nbd.
 
Back
Top