Updated init-functions to be more thorough in checking pids

This commit is contained in:
2018-10-05 16:54:46 -05:00
parent c6456ba7d3
commit 795ed0feaa
2 changed files with 44 additions and 10 deletions

View File

@@ -18,7 +18,7 @@ DESC = This package supplies the core required init scripts for startup
ARCHIVE := ''
SRCDIR := $(PWD)/SRC/initscripts
PATCHDIR := $(PWD)/SRC/patches
VERSION := 1.10-0
VERSION := 1.11-0
include /usr/share/snap/Makefile.snaplinux

View File

@@ -117,9 +117,7 @@ pidofproc() {
esac
done
if [ -n "$pidfile" ] && [ ! -r "$pidfile" ]; then
return 1
elif [ -n "$pidfile" ]; then
if [ -r "$pidfile" ]; then
pids=$(head -1 $pidfile|sed 's/ \+//g')
else
pids=$(pidof "$pathname")
@@ -189,15 +187,51 @@ status_of_proc() {
esac
done
# Here we use LSB as a reference for the return values:
#
# 0 program is running or service is OK
# 1 program is dead and /var/run pid file exists
# 2 program is dead and /var/lock lock file exists
# 3 program is not running
# 4 program or service status is unknown
# 5-99 reserved for future LSB use
# 100-149 reserved for distribution use
# 150-199 reserved for application use
# 200-254 reserved
#
# As you can see however, for now we just support 0, 1, 3 and 4
# May do something for 2 at some point, but the other status
# codes should not be used here - they're only here for reference
if [ -n "$pidfile" ]; then
pid=$(pidofproc -p "$pidfile" "$pathname");
if [ -r "$pidfile" ]; then
pid=$(pidofproc -p "$pidfile" "$pathname")
if [ "$?" -eq 0 ]; then
echo "$NAME running with PID: $pid" && return 0
else
echo "$NAME is not running" && return 1
fi
else
echo "Cannot read pid file ($pidfile)"
pid=$(pidofproc "$pathname")
if [ "$?" -eq 0 ]; then
echo "$NAME running with PID: $pid"
else
echo "$NAME is not running"
fi
if [ "$?" -ne 0 ]; then
echo "$NAME is not runing" && return 1
return 4
fi
else
echo "$NAME running with PID: $pid"
pid=$(pidofproc "$pathname")
if [ "$?" -eq 0 ]; then
echo "$NAME running with PID: $pid" && return 0
else
echo "$NAME is not runing" && return 3
fi
fi
}