File: perl-daemon

package info (click to toggle)
liblinux-systemd-perl 1.201600-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 284 kB
  • sloc: perl: 640; makefile: 7
file content (41 lines) | stat: -rwxr-xr-x 1,110 bytes parent folder | download
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
#!/usr/bin/env perl

use v5.20;
use strictures 2;
use sigtrap qw/handler handle_signal normal-signals/;
use experimental qw/smartmatch signatures/;
use Linux::Systemd::Daemon ':all';
use Linux::Systemd::Journal::Write;

my $sleep_max = 8;
my $jnl       = Linux::Systemd::Journal::Write->new;

sub handle_signal($signal) {
    $jnl->print("Got a SIG$signal");
    given ($signal) {
        when ('HUP') {
            sd_notify(reloading => 1, status => 'Reloading configuration...');
            $jnl->print('pretending to reload configuration');
            sleep rand($sleep_max);
            Linux::Systemd::Daemon::notify("READY=1");
        }
        when (/TERM|INT/) {
            sd_notify(stopping => 1, status => 'Shutting down...');
            $jnl->print('pretending to do some clean up tasks');
            sleep rand($sleep_max);
            exit;
        }
    }

}

$jnl->print('pretending to do some initialisation tasks');
sleep rand($sleep_max);

sd_ready();

while (1) {
    $jnl->print('looping');
    sd_notify(watchdog => 1, status => 'Main loop running');
    sleep rand($sleep_max);
}