Can't stop/restart program started by rc.d script (“is not running”)

Hi folks,

I've created this rc script to start gunicorn as a daemon on boot following this article (practical rc scripting).

Bash:
#!/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.

Code:
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
 
you may need something like

command_interpreter="/usr/local/bin/python3.7"
if ps shows your process like python /some/script you need that

debug sh -x /usr/local/etc/rc.d/your_script status
 
Try:

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

You may also need
Code:
command_interpreter="/usr/local/bin/python3.7"
as mentioned.
 
First of all, thank you both.
Indeed changing p to P (uppercase) did work.

I'm going to read about command_interpreter and procname, because just uppercasing was enough, but I'm afraid I might be missing something else and stumble upon other errors.
 
FWIW, by using
Code:
-P
, you're saving the pid of the
Code:
daemon
command and checking that it's running, rather than the actual application. This means that the output of
Code:
service unicorn_appleclue status
will return the wrong PID, as will reading the pid file, so if you were using that PID for other things, like say signaling to rotate logs or something similar, you'll be signaling the wrong process. May not matter in your case, but for other future readers it may.
 
Just my 2 cents here, but sometimes, you need something like
Code:
# /usr/local/etc/rc.d/my_service onerestart
instead of
Code:
# /usr/local/etc/rc.d/my_service restart
. Also,
Code:
# /usr/local/etc/rc.d/my_service onestart
instead of
Code:
# /usr/local/etc/rc.d/my_service start
.
 
Services will refuse to start with service <myservice> start if there's no corresponding <myservice>_enable="YES" in /etc/rc.conf. service <myservice> onestart skips that check.
 
I faced the same problem when trying to daemonize a shell script.

The start command actually started the service
The status command reported that the service was not running
The stop command complained that the service was not running
Running another start command withouth killing the service reported that the service was already running with the correct pid.

I simply added
Code:
command_interpreter="bin/sh"
to the rc script file and it worked
 
Back
Top