NAME

Systemd::Daemon — Write systemd-aware daemons in Perl.

VERSION

Version 0.06.

SYNOPSIS

Note: The module is in experimental state, interface will be changed in the future.

Functions:

use Systemd::Daemon qw{ :funcs };

notify( RELOADING => 1 );
while ( ... ) {
    notify( STATUS => "Loading, $percent\% done" );
    ...
};

notify( READY => 1, STATUS => "Ready" );
...

notify( STOPPING => 1 );
...

Low-level bare C functions:

use Systemd::Daemon qw{ :bare };

sd_notify( 0, "READY=1\nSTATUS=Ready\n" );
sd_pid_notify( $pid, 0, "READ=1\nSTATUS=Ready\n" );
if ( sd_booted() > 0 ) { ... };

EXPORT

No functions are exported by default. There are 3 import tags:

:funcs

Import higher-level Perl wrappers.

:bare

Import low-level bare C functions.

:all

Import all the functions.

Also, each function can be imported individually, e. g.:

use Systemd::Daemon qw{ notify };

SUBROUTINES

Perl subroutines

notify( VAR => VALUE, ... )

notify is Perl wrapper for C functions sd_notify and sd_pid_notify, so read sd_notify(3) first.

C functions accept status as one string of newline-separated variable assignments, e. g.:

sd_notify( 0, "RELOADING=1\nSTATUS=50% done\n" );

Unlike to C functions, notify accepts each variable separately as Perl "named arguments", e. g.:

notify( RELOADING => 1, STATUS => '50% done' );

unset_environment and pid parameters can be specified as named arguments unset and pid respectively, e. g.:

notify( pid => $pid, unset => 1, ... );

If pid value is defined and not zero, notify calls sd_pid_notify, otherwise sd_notify is called. unset is defaulted to zero.

sd_notify(3) describes some "well-known" variable assignments, for example, RELOADING=1. Systemd's reaction on assignment RELOADING=2 is not defined. In my experiments with systemd v217 any value but 1 does not have any effect. To make notify more Perlish, READY, RELOADING, STOPPING, and WATCHDOG arguments are normalized: if its value is false (e. g. undef, zero or empty string), the respective variable is not passed to underlying C function; if its value is true (not false), the respective variable is set to 1.

notify returns result of underlying sd_notify (or sd_pid_notify). It should be negative integer in case of error, zero if $ENV{ NOTIFY_SOCKET } is not set (and so, systemd cannot be notified), and some positive value in case of success. However, sd_notify(3) recommends to ignore return value.

C subroutines

Low-level bare C functions:

int sd_notify( int unset_environment, const char * state );
int sd_pid_notify( int pid, int unset_environment, const char * state );

See sd_notify(3).

int sd_booted( void );

See sd_booted(3).

int sd_watchdog_enabled( int unset_environment, uint64_t * usec );

See sd_watchdog_enabled(3).

AUTHOR

Van de Bugger, <van.de.bugger@liamg.moc>

BUGS

Please report any bugs or feature requests to bug-systemd-daemon at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Systemd-Daemon. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Systemd::Daemon

You can also look for information at:

ACKNOWLEDGEMENTS

TODO

LICENSE AND COPYRIGHT

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Copyright © 2015 Van de Bugger.