From 03b7b20ce7aa394d80c159de55c7ec2c69f3849c Mon Sep 17 00:00:00 2001 From: Jesse Jarzynka Date: Thu, 3 Nov 2016 13:33:19 -0400 Subject: [PATCH] Fix SysV pid_file to be consistent when ran from a differently named symlink SysV init scripts are ran on boot from symlinks in `/etc/rc.d/rc.X`, where X is the runlevel. These symlinks are usually named something like `S99foobar`, which is a link to the real script `foobar`. This leads to differences in the pid_file filename and can lead to multiple processes running. By using readlink to get the actual destination filename, the pid_file name should always be consistent. Resolves: #78 --- service_sysv_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service_sysv_linux.go b/service_sysv_linux.go index 352847a..9f37dcb 100644 --- a/service_sysv_linux.go +++ b/service_sysv_linux.go @@ -171,7 +171,7 @@ const sysvScript = `#!/bin/sh cmd="{{.Path}}{{range .Arguments}} {{.|cmd}}{{end}}" -name=$(basename $0) +name=$(basename $(readlink -f $0)) pid_file="/var/run/$name.pid" stdout_log="/var/log/$name.log" stderr_log="/var/log/$name.err"