$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
my $daemon_initialized = 0; # we only allow one instance
+my $daemon_sockets = [];
my $close_daemon_lock = sub {
my ($self) = @_;
$ENV{RESTART_PVE_DAEMON} = 1;
+ foreach my $ds (@$daemon_sockets) {
+ $ds->fcntl(Fcntl::F_SETFD(), 0);
+ }
+
if ($self->{max_workers}) {
my @workers = keys %{$self->{workers}};
push @workers, keys %{$self->{old_workers}};
return $pid;
};
+# checks if the process was started by systemd
+my $init_ppid = sub {
+
+ if (getppid() == 1) {
+ return 1;
+ } else {
+ return 0;
+ }
+};
+
sub running {
my ($self) = @_;
code => sub {
my ($param) = @_;
- $self->start($param->{debug});
+ if (&$init_ppid()) {
+ $self->start($param->{debug});
+ } else {
+ PVE::Tools::run_command(['systemctl', 'start', $self->{name}]);
+ }
return undef;
}});
code => sub {
my ($param) = @_;
- &$reload_daemon($self, $use_hup);
+ if (&$init_ppid()) {
+ &$reload_daemon($self, $use_hup);
+ } else {
+ PVE::Tools::run_command(['systemctl', $use_hup ? 'reload-or-restart' : 'restart', $self->{name}]);
+ }
return undef;
}});
code => sub {
my ($param) = @_;
- $self->stop();
+ if (&$init_ppid()) {
+ $self->stop();
+ } else {
+ PVE::Tools::run_command(['systemctl', 'stop', $self->{name}]);
+ }
return undef;
}});
$socket->fdopen($sockfd, 'w') ||
die "cannot fdopen file descriptor '$sockfd' - $!\n";
+ $socket->fcntl(Fcntl::F_SETFD(), Fcntl::FD_CLOEXEC);
} else {
$socket = IO::Socket::IP->new(
$ENV{"PVE_DAEMON_SOCKET_$port"} = $socket->fileno;
}
- # remove FD_CLOEXEC bit to reuse on exec
- $socket->fcntl(Fcntl::F_SETFD(), 0);
-
+ push @$daemon_sockets, $socket;
+
return $socket;
}