mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
Misc fixes for cleanup/cancel handling
This commit is contained in:
parent
433c302672
commit
8de208ac76
3 changed files with 34 additions and 25 deletions
|
@ -19,16 +19,6 @@ LXC_NAME="ynh-appci-$DIST-$ARCH-$YNH_BRANCH-test"
|
||||||
|
|
||||||
readonly lock_file="./pcheck.lock"
|
readonly lock_file="./pcheck.lock"
|
||||||
|
|
||||||
clean_exit () {
|
|
||||||
|
|
||||||
LXC_RESET
|
|
||||||
|
|
||||||
[ -n "$TEST_CONTEXT" ] && rm -rf "$TEST_CONTEXT"
|
|
||||||
rm -f "$lock_file"
|
|
||||||
|
|
||||||
exit $1
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LXC helpers
|
# LXC helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -124,7 +114,7 @@ function log_error()
|
||||||
function log_critical()
|
function log_critical()
|
||||||
{
|
{
|
||||||
echo "${BOLD}${RED}Critical: ${1}${NORMAL}" | tee -a /proc/self/fd/3
|
echo "${BOLD}${RED}Critical: ${1}${NORMAL}" | tee -a /proc/self/fd/3
|
||||||
clean_exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function log_report_test_success () {
|
function log_report_test_success () {
|
||||||
|
|
|
@ -12,7 +12,7 @@ LXC_CREATE () {
|
||||||
-c limits.cpu.allowance=80% \
|
-c limits.cpu.allowance=80% \
|
||||||
| grep -v -E "^\s*Remapping container filesystem\s*$\|^\s*Retrieving image"
|
| grep -v -E "^\s*Remapping container filesystem\s*$\|^\s*Retrieving image"
|
||||||
|
|
||||||
[[ "${PIPESTATUS[0]}" -eq 0 ]] || clean_exit 1
|
[[ "${PIPESTATUS[0]}" -eq 0 ]] || exit 1
|
||||||
|
|
||||||
_LXC_START_AND_WAIT $LXC_NAME
|
_LXC_START_AND_WAIT $LXC_NAME
|
||||||
set_witness_files
|
set_witness_files
|
||||||
|
|
|
@ -117,10 +117,17 @@ function parse_args() {
|
||||||
arguments=("$@")
|
arguments=("$@")
|
||||||
parse_args
|
parse_args
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# Cleanup / force-stop
|
||||||
|
#=================================================
|
||||||
|
|
||||||
#=================================================
|
function cleanup()
|
||||||
# Force-stop
|
{
|
||||||
#=================================================
|
LXC_RESET
|
||||||
|
|
||||||
|
[ -n "$TEST_CONTEXT" ] && rm -rf "$TEST_CONTEXT"
|
||||||
|
[ -n "$lock_file" ] && rm -f "$lock_file"
|
||||||
|
}
|
||||||
|
|
||||||
if [[ $force_stop == 1 ]]
|
if [[ $force_stop == 1 ]]
|
||||||
then
|
then
|
||||||
|
@ -128,36 +135,48 @@ then
|
||||||
if [ -n "$package_check_pid" ]; then
|
if [ -n "$package_check_pid" ]; then
|
||||||
kill --signal 15 $package_check_pid
|
kill --signal 15 $package_check_pid
|
||||||
fi
|
fi
|
||||||
clean_exit 0
|
cleanup
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# Check if the lock file exist
|
# Check if the lock file exist
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if test -e "$lock_file"
|
# If the lock file exist and corresponding process still exists
|
||||||
|
if test -e "$lock_file" && ps --pid "$(cat pcheck.lock | cut -d: -f3)" | grep --quiet "$(cat pcheck.lock | cut -d: -f3)"
|
||||||
then
|
then
|
||||||
# If the lock file exist
|
|
||||||
echo "The lock file $lock_file is present. Package check would not continue."
|
|
||||||
if [ $interactive -eq 1 ]; then
|
if [ $interactive -eq 1 ]; then
|
||||||
|
echo "The lock file $lock_file already exists."
|
||||||
echo -n "Do you want to continue anyway? (y/n) :"
|
echo -n "Do you want to continue anyway? (y/n) :"
|
||||||
read answer
|
read answer
|
||||||
|
else
|
||||||
|
log_critical "The lock file $lock_file already exists. Package check won't continue."
|
||||||
fi
|
fi
|
||||||
# Set the answer at lowercase only
|
# Set the answer at lowercase only
|
||||||
answer=${answer,,}
|
answer=${answer,,}
|
||||||
if [ "${answer:0:1}" != "y" ]
|
if [ "${answer:0:1}" != "y" ]
|
||||||
then
|
then
|
||||||
echo "Cancel Package check execution"
|
log_critical "Package check cancelled"
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# Create the lock file
|
# Create the lock file
|
||||||
# $$ is the PID of package_check itself.
|
# $$ is the PID of package_check itself.
|
||||||
echo "start:$(date +%s):$$" > "$lock_file"
|
echo "start:$(date +%s):$$" > "$lock_file"
|
||||||
|
|
||||||
###################################
|
#==========================
|
||||||
|
# Cleanup
|
||||||
|
# N.B. the traps are added AFTER the lock is taken
|
||||||
|
# because we don't want to mess with with the lock and LXC
|
||||||
|
# it we ain't the process with the lock...
|
||||||
|
#==========================
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
|
trap 'exit 2' TERM KILL
|
||||||
|
|
||||||
|
#==========================
|
||||||
# Main code
|
# Main code
|
||||||
###################################
|
#==========================
|
||||||
|
|
||||||
assert_we_are_connected_to_the_internets
|
assert_we_are_connected_to_the_internets
|
||||||
assert_we_have_all_dependencies
|
assert_we_have_all_dependencies
|
||||||
|
@ -165,7 +184,7 @@ assert_we_have_all_dependencies
|
||||||
if [[ $rebuild == 1 ]]
|
if [[ $rebuild == 1 ]]
|
||||||
then
|
then
|
||||||
rebuild_base_lxc 2>&1 | tee -a "./build_base_lxc.log"
|
rebuild_base_lxc 2>&1 | tee -a "./build_base_lxc.log"
|
||||||
clean_exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#self_upgrade # FIXME renenable this later
|
#self_upgrade # FIXME renenable this later
|
||||||
|
@ -176,4 +195,4 @@ readonly TEST_CONTEXT=$(mktemp -d /tmp/package_check.XXXXXX)
|
||||||
fetch_package_to_test "$path_to_package_to_test"
|
fetch_package_to_test "$path_to_package_to_test"
|
||||||
run_all_tests
|
run_all_tests
|
||||||
|
|
||||||
clean_exit 0
|
exit 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue