0

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

#!/bin/sh

# PROVIDE: gunicorn_appleclue 
# REQUIRE: DAEMON

. /etc/rc.subr

name=gunicorn_appleclue
rcvar=gunicorn_appleclue_enable

pidfile="/var/run/gunicorn/${name}.pid"

command="/usr/sbin/daemon"
command_args="-p ${pidfile} -r -t django_appleclue /home/victor/.venv/appleclue/bin/gunicorn -b 0.0.0.0:8001 -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?

Thanks

Victor Ribeiro
  • 161
  • 1
  • 6
  • 1
    Make sure the PID is really running. Run shell> ps ax | grep \`cat /var/run/gunicorn/gunicorn_appleclue.pid\` – Vladimir Botka May 16 '21 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" – Victor Ribeiro May 16 '21 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`. – Richard Smith May 17 '21 at 09:54

1 Answers1

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:

procname="/home/victor/.venv/appleclue/bin/gunicorn"

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

Steve Wills
  • 685
  • 3
  • 6