public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] How does OpenRC know if a service is crashed?
@ 2018-08-02  9:32 Alarig Le Lay
  2018-08-02 10:30 ` Manuel Mommertz
  0 siblings, 1 reply; 3+ messages in thread
From: Alarig Le Lay @ 2018-08-02  9:32 UTC (permalink / raw
  To: gentoo-user

Hi,

Some times ago, I wrote a basic init script for a service I’m running
but that is not in the tree.
It’s just a python script behind a reverse-proxy.

bulbizarre ~ # cat /etc/init.d/paste-py
#!/sbin/openrc-run
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

#depend() {
#
#}

start() {
        start-stop-daemon --start --user pastepy --exec paste-py.sh --name paste-py
        eend $?
}

stop() {
        kill $(cat /opt/paste-py/paste.pid)
}
bulbizarre ~ # cat $(which paste-py.sh)
#!/bin/sh

port="$(grep port /opt/paste-py/paste-py.conf | cut -d '=' -f 2)"
addr="$(grep addr /opt/paste-py/paste-py.conf | cut -d '=' -f 2)"

cd /opt/paste-py
source bin/activate
./daemonize.py --port=${port} --addr=${addr}
bulbizarre ~ # cat /opt/paste-py/paste.pid
9480
bulbizarre ~ # ps aux | grep 9480
root       493  0.0  0.0  11440   924 pts/3    S+   11:14   0:00 grep --colour=auto 9480
pastepy   9480  0.0  0.4 113548 16848 ?        S    08:05   0:00 python ./daemonize.py --port=8087 --addr=127.0.0.1

So, the process is running (and responding), but OpenRC shows it as
crashed

bulbizarre ~ # rc-status | grep crash
 paste-py                                                          [  crashed  ]

What do I have to change?

Thanks,
-- 
alarig


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-user] How does OpenRC know if a service is crashed?
  2018-08-02  9:32 [gentoo-user] How does OpenRC know if a service is crashed? Alarig Le Lay
@ 2018-08-02 10:30 ` Manuel Mommertz
  2018-08-02 12:05   ` Alarig Le Lay
  0 siblings, 1 reply; 3+ messages in thread
From: Manuel Mommertz @ 2018-08-02 10:30 UTC (permalink / raw
  To: gentoo-user

Am Donnerstag, 2. August 2018, 11:32:23 CEST schrieb Alarig Le Lay:
> Hi,
> 
> Some times ago, I wrote a basic init script for a service I?m running
> but that is not in the tree.
> It?s just a python script behind a reverse-proxy.
> 
> bulbizarre ~ # cat /etc/init.d/paste-py
> #!/sbin/openrc-run
> # Copyright 1999-2015 Gentoo Foundation
> # Distributed under the terms of the GNU General Public License v2
> # $Header: $
> 
> #depend() {
> #
> #}
> 
> start() {
>         start-stop-daemon --start --user pastepy --exec paste-py.sh --name
> paste-py eend $?
> }
> 
> stop() {
>         kill $(cat /opt/paste-py/paste.pid)
> }
> bulbizarre ~ # cat $(which paste-py.sh)
> #!/bin/sh
> 
> port="$(grep port /opt/paste-py/paste-py.conf | cut -d '=' -f 2)"
> addr="$(grep addr /opt/paste-py/paste-py.conf | cut -d '=' -f 2)"
> 
> cd /opt/paste-py
> source bin/activate
> ./daemonize.py --port=${port} --addr=${addr}
> bulbizarre ~ # cat /opt/paste-py/paste.pid
> 9480
> bulbizarre ~ # ps aux | grep 9480
> root       493  0.0  0.0  11440   924 pts/3    S+   11:14   0:00 grep
> --colour=auto 9480 pastepy   9480  0.0  0.4 113548 16848 ?        S   
> 08:05   0:00 python ./daemonize.py --port=8087 --addr=127.0.0.1
> 
> So, the process is running (and responding), but OpenRC shows it as
> crashed
> 
> bulbizarre ~ # rc-status | grep crash
>  paste-py                                                          [ 
> crashed  ]
> 
> What do I have to change?
> 
> Thanks,

Hey Alarig,

I suggest to read the man-page of start-stop-daemon to get an detailed idea of 
how it works.

You use '--name paste-py' which tells start-stop-daemon to look for a process 
named 'paste-py' to see if it is still running, when you request the status. 
As your shell-script runs daemonize.py as the last step and then quits itself, 
there is no process with the name 'paste-py' and therefore the reported status 
is 'crashed'.
Use '--pidfile /opt/paste-py/paste.pid' instead. With this, the status is 
determined by reading the pid from the file and then looking if this pid is 
still running.

Greets
Manuel




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-user] How does OpenRC know if a service is crashed?
  2018-08-02 10:30 ` Manuel Mommertz
@ 2018-08-02 12:05   ` Alarig Le Lay
  0 siblings, 0 replies; 3+ messages in thread
From: Alarig Le Lay @ 2018-08-02 12:05 UTC (permalink / raw
  To: gentoo-user

Hi Manuel

On jeu.  2 août 12:30:16 2018, Manuel Mommertz wrote:
> Hey Alarig,
> 
> I suggest to read the man-page of start-stop-daemon to get an detailed idea of 
> how it works.
> 
> You use '--name paste-py' which tells start-stop-daemon to look for a process 
> named 'paste-py' to see if it is still running, when you request the status. 
> As your shell-script runs daemonize.py as the last step and then quits itself, 
> there is no process with the name 'paste-py' and therefore the reported status 
> is 'crashed'.
> Use '--pidfile /opt/paste-py/paste.pid' instead. With this, the status is 
> determined by reading the pid from the file and then looking if this pid is 
> still running.

Thanks a lot it’s now displayed as running :)
bulbizarre ~ # rc-status | grep paste
 paste-py                                                          [  started  ]

-- 
alarig


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-02 12:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-02  9:32 [gentoo-user] How does OpenRC know if a service is crashed? Alarig Le Lay
2018-08-02 10:30 ` Manuel Mommertz
2018-08-02 12:05   ` Alarig Le Lay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox