summaryrefslogtreecommitdiffstats
path: root/cts/support/pacemaker-cts-dummyd.in
blob: 453a644673d0b2bffa18b97dad39df46858ea481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!@PYTHON@
""" Slow-starting idle daemon that notifies systemd when it starts
"""

__copyright__ = "Copyright 2014-2020 the Pacemaker project contributors"
__license__ = "GNU General Public License version 2 or later (GPLv2+) WITHOUT ANY WARRANTY"

import sys
import time
import signal
import subprocess
have_systemd_daemon = True
try:
    import systemd.daemon
except ImportError:
    have_systemd_daemon = False

delay = None

def parse_args():
    global delay

    # Lone argument is a number of seconds to delay start and stop
    if len(sys.argv) > 0:
        try:
            delay = float(sys.argv[1])
        except ValueError:
            delay = None


def twiddle():
    global delay

    if delay is not None:
        time.sleep(delay)


def bye(signum, frame):
    twiddle()
    sys.exit(0)


if __name__ == "__main__":

    parse_args()
    signal.signal(signal.SIGTERM, bye)
    twiddle()
    if have_systemd_daemon:
        systemd.daemon.notify("READY=1")
    else:
        subprocess.call(["systemd-notify", "READY=1"])

    # This isn't a "proper" daemon, but that would be overkill for testing purposes
    while True:
        time.sleep(600.0)