Gentoo Archives: gentoo-user

From: Manuel Mommertz <2kmm@×××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] How does OpenRC know if a service is crashed?
Date: Thu, 02 Aug 2018 10:30:43
Message-Id: 6872387.OOkRybvtOo@osiris
In Reply to: [gentoo-user] How does OpenRC know if a service is crashed? by Alarig Le Lay
1 Am Donnerstag, 2. August 2018, 11:32:23 CEST schrieb Alarig Le Lay:
2 > Hi,
3 >
4 > Some times ago, I wrote a basic init script for a service I?m running
5 > but that is not in the tree.
6 > It?s just a python script behind a reverse-proxy.
7 >
8 > bulbizarre ~ # cat /etc/init.d/paste-py
9 > #!/sbin/openrc-run
10 > # Copyright 1999-2015 Gentoo Foundation
11 > # Distributed under the terms of the GNU General Public License v2
12 > # $Header: $
13 >
14 > #depend() {
15 > #
16 > #}
17 >
18 > start() {
19 > start-stop-daemon --start --user pastepy --exec paste-py.sh --name
20 > paste-py eend $?
21 > }
22 >
23 > stop() {
24 > kill $(cat /opt/paste-py/paste.pid)
25 > }
26 > bulbizarre ~ # cat $(which paste-py.sh)
27 > #!/bin/sh
28 >
29 > port="$(grep port /opt/paste-py/paste-py.conf | cut -d '=' -f 2)"
30 > addr="$(grep addr /opt/paste-py/paste-py.conf | cut -d '=' -f 2)"
31 >
32 > cd /opt/paste-py
33 > source bin/activate
34 > ./daemonize.py --port=${port} --addr=${addr}
35 > bulbizarre ~ # cat /opt/paste-py/paste.pid
36 > 9480
37 > bulbizarre ~ # ps aux | grep 9480
38 > root 493 0.0 0.0 11440 924 pts/3 S+ 11:14 0:00 grep
39 > --colour=auto 9480 pastepy 9480 0.0 0.4 113548 16848 ? S
40 > 08:05 0:00 python ./daemonize.py --port=8087 --addr=127.0.0.1
41 >
42 > So, the process is running (and responding), but OpenRC shows it as
43 > crashed
44 >
45 > bulbizarre ~ # rc-status | grep crash
46 > paste-py [
47 > crashed ]
48 >
49 > What do I have to change?
50 >
51 > Thanks,
52
53 Hey Alarig,
54
55 I suggest to read the man-page of start-stop-daemon to get an detailed idea of
56 how it works.
57
58 You use '--name paste-py' which tells start-stop-daemon to look for a process
59 named 'paste-py' to see if it is still running, when you request the status.
60 As your shell-script runs daemonize.py as the last step and then quits itself,
61 there is no process with the name 'paste-py' and therefore the reported status
62 is 'crashed'.
63 Use '--pidfile /opt/paste-py/paste.pid' instead. With this, the status is
64 determined by reading the pid from the file and then looking if this pid is
65 still running.
66
67 Greets
68 Manuel

Replies

Subject Author
Re: [gentoo-user] How does OpenRC know if a service is crashed? Alarig Le Lay <alarig@××××××××××.fr>