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

vicmarconi

New Member

Reaction score: 3
Messages: 4

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
 

covacat

Well-Known Member

Reaction score: 225
Messages: 471

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
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 12,342
Messages: 38,859

Try -P ${pidfile} instead of -p ${pidfile}.
 

swills@

Member
Developer

Reaction score: 20
Messages: 78

Try:

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

You may also need
Code:
command_interpreter="/usr/local/bin/python3.7"
as mentioned.
 
OP
vicmarconi

vicmarconi

New Member

Reaction score: 3
Messages: 4

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.
 

swills@

Member
Developer

Reaction score: 20
Messages: 78

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.
 

astyle

Daemon

Reaction score: 481
Messages: 1,111

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
.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 12,342
Messages: 38,859

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.
 
Top