From 585a442b64b9c98f7514c9b31275611ef3d67d9e Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 30 May 2017 21:23:20 +0100 Subject: [PATCH] move old PID file to new name --- bin/netdisco-daemon | 23 ++++++++++++++--------- bin/netdisco-daemon-fg | 18 +++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/bin/netdisco-daemon b/bin/netdisco-daemon index 7591827e..2ac25b39 100755 --- a/bin/netdisco-daemon +++ b/bin/netdisco-daemon @@ -3,17 +3,22 @@ use strict; use warnings; -use File::Spec; -use Cwd 'realpath'; - use FindBin; FindBin::again(); -my $backend = - File::Spec->catfile( - (File::Spec->splitpath( - realpath(File::Spec->catfile( $FindBin::RealBin, $FindBin::RealScript )) - ))[1], - 'netdisco-backend'); +use File::Spec; +use Path::Class; +use Cwd 'realpath'; +use File::Copy 'move'; +my $me = realpath(File::Spec->catfile($FindBin::RealBin, $FindBin::RealScript)); +my $uid = (stat($me))[4] || 0; +my $home = ($ENV{NETDISCO_HOME} || (getpwuid($uid))[7] || $ENV{HOME}); + +my $old_pid = file($home, 'netdisco-daemon.pid'); +my $new_pid = file($home, 'netdisco-backend.pid'); +if (-f $old_pid) { move( $old_pid, $new_pid ) } + +my $backend = + File::Spec->catfile((File::Spec->splitpath( $me ))[1], 'netdisco-backend'); exec {$backend} 'netdisco-backend', @ARGV; diff --git a/bin/netdisco-daemon-fg b/bin/netdisco-daemon-fg index fefbe258..e487dca0 100755 --- a/bin/netdisco-daemon-fg +++ b/bin/netdisco-daemon-fg @@ -3,17 +3,17 @@ use strict; use warnings; -use File::Spec; -use Cwd 'realpath'; - use FindBin; FindBin::again(); -my $backend = - File::Spec->catfile( - (File::Spec->splitpath( - realpath(File::Spec->catfile( $FindBin::RealBin, $FindBin::RealScript )) - ))[1], - 'netdisco-backend-fg'); +use File::Spec; +use Path::Class; +use Cwd 'realpath'; +my $me = realpath(File::Spec->catfile($FindBin::RealBin, $FindBin::RealScript)); +my $uid = (stat($me))[4] || 0; +my $home = ($ENV{NETDISCO_HOME} || (getpwuid($uid))[7] || $ENV{HOME}); + +my $backend = + File::Spec->catfile((File::Spec->splitpath( $me ))[1], 'netdisco-backend-fg'); exec {$backend} 'netdisco-backend-fg', @ARGV;