[pve-devel] [PATCH] PVE:Daemon start/restart with systemd
Dietmar Maurer
dietmar at proxmox.com
Tue Jun 16 16:48:27 CEST 2015
some comments inline
> diff --git a/src/PVE/Daemon.pm b/src/PVE/Daemon.pm
> index e051500..16e08c9 100644
> --- a/src/PVE/Daemon.pm
> @@ -578,6 +578,16 @@ my $read_pid = sub {
> return $pid;
> };
>
> +my $init_ppid = sub {
> + my $ppid = getppid();
> +
> + if ($ppid == 1) {
> + return 1;
> + } else {
> + return 0;
> + }
> +};
> +
> sub running {
> my ($self) = @_;
>
> @@ -654,7 +664,11 @@ sub register_start_command {
> 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;
> }});
> @@ -666,7 +680,7 @@ my $reload_daemon = sub {
> if ($self->{env_restart_pve_daemon}) {
> $self->start();
> } else {
> - my ($running, $pid) = $self->running();
> + my ($running, $pid) = $self->running();
useless?
> if (!$running) {
> $self->start();
> } else {
> @@ -700,8 +714,23 @@ sub register_restart_command {
> code => sub {
> my ($param) = @_;
>
> - &$reload_daemon($self, $use_hup);
> -
> + if (&$init_ppid()) {
> + &$reload_daemon($self, $use_hup);
> + } else {
> + my ($running, $pid) = $self->running();
> + if (!$running) {
> + PVE::Tools::run_command(['systemctl', 'start',
> $self->{name}]);
> + } else {
> + if ($use_hup) {
> + syslog('info', "send HUP to $pid");
> + kill 1, $pid;
> + PVE::Tools::run_command(['systemctl', 'start',
> $self->{name}]);
It is already running, so what is the purpose of that 'start'?
> + } else {
> + PVE::Tools::run_command(['systemctl', 'restart',
> $self->{name}]);
> + }
> + }
> + }
> +
I thought we can simply use the following?
if (&$init_ppid()) {
&$reload_daemon($self, $use_hup);
} else {
PVE::Tools::run_command(['systemctl', $use_hup ? 'reload-or-restart' :
'restart', $self->{name}]);
}
We also want to use systemctl to stop the service.
More information about the pve-devel
mailing list