Skip to content
Snippets Groups Projects
Commit 54c59f46 authored by Sergey Joseph Ivanov's avatar Sergey Joseph Ivanov
Browse files

Systemd require pidfile for forking daemons

Added option -r <pidfile> for resmon.
If none provided it will run without creating pidfile.
If provided, it will try write it's pid into specified file.
Resmon-systemd.service should have this file as an argument for
resmon as a PIDFile option and in ExecStart option.
parent b031161a
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ use POSIX qw( :sys_wait_h setsid );
use Getopt::Long;
use Data::Dumper;
use vars qw($config_file $debug $status_file $interface $port $config
$status $update);
$status $update $pid_file);
use Resmon::Config;
use Resmon::ExtComm;
......@@ -26,6 +26,7 @@ GetOptions(
"d" => \$debug,
"f=s" => \$status_file,
"u" => \$update,
"r=s" => \$pid_file,
);
if ($update) {
......@@ -42,6 +43,7 @@ sub configure {
$config->{statusfile} = $status_file if($status_file);
$config->{port} = $port if($port);
$config->{interface} = $interface if($interface);
$config->{pidfile} = $pid_file if ($pid_file);
}
configure();
......@@ -77,7 +79,15 @@ unless($debug) {
open(STDIN, "</dev/null");
open(STDOUT, ">/dev/null");
open(STDERR, ">/dev/null");
fork && exit;
my $pid=fork;
if ($pid) {
if (my $PIDFILE=$config->{pidfile}) {
open(PIDFILE,">$PIDFILE") or die "can't open >$PIDFILE";
print PIDFILE $pid;
close PIDFILE or die "can't close $PIDFILE";
}
exit;
}
}
my $list = [];
......
......@@ -5,8 +5,10 @@ After=network.target
[Service]
Type=forking
ExecStart=/opt/resmon/resmon
ExecStart=/opt/resmon/resmon -r /run/resmon.pid
Restart=on-failure
PIDFile=/run/resmon.pid
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment