mirror of
https://github.com/deajan/obackup.git
synced 2024-11-14 11:43:41 +01:00
Added new killtree function
This commit is contained in:
parent
6dd92b03f8
commit
62600fff39
@ -21,6 +21,7 @@ UNDER WORK
|
|||||||
|
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
---------
|
---------
|
||||||
|
- New function to kill child processes
|
||||||
- Fixed no_maxtime not honored
|
- Fixed no_maxtime not honored
|
||||||
- Improved some logging, also added highlighting to stdout errors
|
- Improved some logging, also added highlighting to stdout errors
|
||||||
- Backported some fixes from Osync
|
- Backported some fixes from Osync
|
||||||
|
53
obackup.sh
53
obackup.sh
@ -5,7 +5,7 @@
|
|||||||
AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong"
|
AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong"
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||||
PROGRAM_VERSION=1.9pre
|
PROGRAM_VERSION=1.9pre
|
||||||
PROGRAM_BUILD=2015090603
|
PROGRAM_BUILD=2015091401
|
||||||
|
|
||||||
## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode
|
## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode
|
||||||
if ! type -p "$BASH" > /dev/null
|
if ! type -p "$BASH" > /dev/null
|
||||||
@ -110,6 +110,21 @@ function LogDebug
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Highly portable killtree function from http://stackoverflow.com/a/18214698/2635443, modded not to kill itself
|
||||||
|
function KillTree {
|
||||||
|
local parent=$1 child
|
||||||
|
|
||||||
|
for child in $(ps -o ppid= -o pid= | awk "\$1==$parent {print \$2}"); do
|
||||||
|
KillTree $child
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $parent -ne $$ ]; then
|
||||||
|
kill -9 $parent > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
killtree $$
|
||||||
|
|
||||||
function TrapError
|
function TrapError
|
||||||
{
|
{
|
||||||
local JOB="$0"
|
local JOB="$0"
|
||||||
@ -130,35 +145,35 @@ function TrapStop
|
|||||||
function TrapQuit
|
function TrapQuit
|
||||||
{
|
{
|
||||||
# Kill all child processes
|
# Kill all child processes
|
||||||
if type -p pkill > /dev/null 2>&1
|
#if type -p pkill > /dev/null 2>&1
|
||||||
then
|
#then
|
||||||
## Added || : to return success even if there is no child process to kill
|
# ## Added || : to return success even if there is no child process to kill
|
||||||
pkill -TERM -P $$ || :
|
# pkill -TERM -P $$ || :
|
||||||
elif [ "$LOCAL_OS" == "msys" ] || [ "$OSTYPE" == "msys" ]
|
#elif [ "$LOCAL_OS" == "msys" ] || [ "$OSTYPE" == "msys" ]
|
||||||
then
|
#then
|
||||||
## This is not really a clean way to get child process pids, especially the tail -n +2 which resolves a strange char apparition in msys bash
|
## This is not really a clean way to get child process pids, especially the tail -n +2 which resolves a strange char apparition in msys bash
|
||||||
for pid in $(ps -a | awk '{$1=$1}$1' | awk '{print $1" "$2}' | grep " $$$" | awk '{print $1}' | tail -n +2)
|
# for pid in $(ps -a | awk '{$1=$1}$1' | awk '{print $1" "$2}' | grep " $$$" | awk '{print $1}' | tail -n +2)
|
||||||
do
|
# do
|
||||||
kill -9 $pid > /dev/null 2>&1
|
# kill -9 $pid > /dev/null 2>&1
|
||||||
done
|
# done
|
||||||
else
|
#else
|
||||||
for pid in $(ps -a --Group $$)
|
# for pid in $(ps -a --Group $$)
|
||||||
do
|
# do
|
||||||
kill -9 $pid
|
# kill -9 $pid
|
||||||
done
|
# done
|
||||||
fi
|
#fi
|
||||||
|
|
||||||
if [ $error_alert -ne 0 ]
|
if [ $error_alert -ne 0 ]
|
||||||
then
|
then
|
||||||
SendAlert
|
SendAlert
|
||||||
CleanUp
|
CleanUp
|
||||||
LogError "Backup script finished with errors."
|
LogError "Backup script finished with errors."
|
||||||
exit 1
|
|
||||||
else
|
else
|
||||||
CleanUp
|
CleanUp
|
||||||
Log "Backup script finshed."
|
Log "Backup script finshed."
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
KillTree $$
|
||||||
}
|
}
|
||||||
|
|
||||||
function Spinner
|
function Spinner
|
||||||
|
Loading…
Reference in New Issue
Block a user