I've created a rc script to start gunicorn as a daemon on boot.


# PROVIDE: gunicorn_appleclue 

. /etc/rc.subr



command_args="-p ${pidfile} -r -t django_appleclue /home/victor/.venv/appleclue/bin/gunicorn -b -w 4 --pythonpath /home/victor/applications/appleclue/appleclue-web appleclue.wsgi"

load_rc_config $name
run_rc_command "$1"

It's working in a sense that after booting, the service is up. But the problem I'm facing is when trying stop/restart the service.

sudo service gunicorn_appleclue stop
gunicorn_appleclue not running? (check /var/run/gunicorn/gunicorn_appleclue.pid).

ls -la /var/run/gunicorn/gunicorn_appleclue.pid
-rw-------  1 root  wheel  3 May 15 14:25 /var/run/gunicorn/gunicorn_appleclue.pid

So, gunicorn is running and the pidfile is where it asked me. Is there anything I'm missing?


  • 1
    Make sure the PID is really running. Run shell> ps ax | grep `cat /var/run/gunicorn/gunicorn_appleclue.pid` May 16, 2021 at 21:36
  • I couldn't run exactly this command. Had to remove "cat" and the backticks. It returned: "76844 0 S+ 0:00.00 grep /var/run/gunicorn/gunicorn_appleclue.pid" Then, cat /var/run/gunicorn/gunicorn_appleclue.pid returned "934" May 16, 2021 at 22:32
  • 1
    You are using -p with -r, and the manual suggests that you should use -P when using -r. That's uppercase P. May 17, 2021 at 9:54

1 Answer 1


You need to set the procname as well, since rc.subr checks both the pid and the name of that process to match what it expects, in case the command died and some other process happened to have gotten the same pid.

So, add a line after rcvar like this:


For more details, see rc.subr or read /etc/rc.subr.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.