mirror of
https://github.com/sbopkg/sbopkg
synced 2024-12-29 10:24:11 +01:00
pid_check: verify older PID's existence.
If $PIDFILE exists, verify whether it refers to a running process. This way the amount of false positives is greatly reduced, which is a good thing during development when a crash can terminate sbopkg leaving the $PIDFILE in place. Signed-off-by: Mauro Giachero <mauro.giachero@gmail.com>
This commit is contained in:
parent
52cbcbcbde
commit
cd1f6aa495
1 changed files with 23 additions and 11 deletions
|
@ -133,20 +133,32 @@ directory_checks () {
|
||||||
|
|
||||||
pid_check () {
|
pid_check () {
|
||||||
# Set and check for pid file.
|
# Set and check for pid file.
|
||||||
|
local PIDFILE OTHERPID
|
||||||
|
|
||||||
PIDFILE=$TMP/sbopkg.pid
|
PIDFILE=$TMP/sbopkg.pid
|
||||||
if [ -e $PIDFILE ]; then
|
if [ -e $PIDFILE ]; then
|
||||||
echo
|
# When things go haywire and sbopkg crashes (this happens only on
|
||||||
echo "Another instance of sbopkg appears to be running"
|
# development versions, of course ;-)) the PIDFILE isn't deleted and
|
||||||
echo "with process id $(cat $PIDFILE). Running more than"
|
# triggers the error below on the following run.
|
||||||
echo "one instance of sbopkg is not recommended."
|
# Perform a basic test to reduce the amount of false positives. Note
|
||||||
echo
|
# that no check on the file name is performed, to avoid missing true
|
||||||
echo "If this is incorrect, you can delete the lockfile"
|
# positives in the (rare, but possible) cases where the user renames
|
||||||
echo "'${PIDFILE}' and restart. Exiting now."
|
# the sbopkg script.
|
||||||
exit 1
|
OTHERPID=$(cat $PIDFILE)
|
||||||
else
|
if [[ -n $(ps h --pid $OTHERPID) ]]; then
|
||||||
cleanup
|
echo
|
||||||
echo $$ > $PIDFILE
|
echo "Another instance of sbopkg appears to be running"
|
||||||
|
echo "with process id $OTHERPID. Running more than"
|
||||||
|
echo "one instance of sbopkg is not recommended."
|
||||||
|
echo
|
||||||
|
echo "If this is incorrect, you can delete the lockfile"
|
||||||
|
echo "'${PIDFILE}' and restart. Exiting now."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
echo $$ > $PIDFILE
|
||||||
}
|
}
|
||||||
|
|
||||||
has_root () {
|
has_root () {
|
||||||
|
|
Loading…
Reference in a new issue