Exit if any proc related to maco runs

This commit is contained in:
Jeremy Gardais 2020-06-24 11:51:24 +02:00
parent 9549db7a17
commit 0141ec027b
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 30 additions and 0 deletions

View File

@ -42,6 +42,29 @@ debug_message() { # {{{
## Print message if DEBUG is enable (=0) ## Print message if DEBUG is enable (=0)
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_message}" [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG ${PROGNAME}: ${local_message}"
}
# }}}
is_proc_running() { # {{{
local_proc_pattern="${1}"
local_count_proc_pattern="$(pgrep -f -- "${local_proc_pattern}" | wc -l)"
case "${local_count_proc_pattern}" in
0 ) ## No procs related to this pattern are running
return_proc_running="1"
;;
* ) ## At least one proc seems running
return_proc_running="0"
;;
esac
## Simple debug message to valid current variables
debug_message "is_proc_running \
procs running (with the pattern: ${RED}${local_proc_pattern}${COLOR_DEBUG}) on the current host: ${RED}${local_count_proc_pattern}${COLOR_DEBUG}."
return "${return_proc_running}"
} }
# }}} # }}}
remove_cron() { # {{{ remove_cron() { # {{{
@ -59,6 +82,13 @@ Try to remove cron jobs (autoupdate, benchmark,…)."
# }}} # }}}
main() { # {{{ main() { # {{{
maco_proc_pattern="(/opt/maco/bin/maco.autoupdate.sh)"
## If anything related to maco is currently running
### Exit
is_proc_running "${maco_proc_pattern}" \
&& exit 0
remove_cron remove_cron
} }