Commit c573ca0c authored by UltimateByte's avatar UltimateByte Committed by GitHub
Browse files

rework for before actions

parent 1162e3e4
...@@ -132,9 +132,15 @@ fn_evaluate(){ ...@@ -132,9 +132,15 @@ fn_evaluate(){
# Execute an action before proceeding # Execute an action before proceeding
fn_actionbefore(){ fn_actionbefore(){
if [ -n "${actionbefore}" ]; then if [ -n "${actionbefore}" ]&&[ "${harm}" == "1" ]&&[ -z "${actiontaken}" ]; then
fn_logecho "[ACTION] Applying actionbefore: ${actionbefore}" fn_logecho "[ACTION] Applying actionbefore: ${actionbefore}"
${actionbefore} ${actionbefore}
actiontaken="1"
refresh="1"
else
# Misc var to tell that an action has been taken
actiontaken="1"
fn_logecho "[ACTION] Refreshing info ${pid}"
fi fi
} }
...@@ -155,23 +161,29 @@ fn_action(){ ...@@ -155,23 +161,29 @@ fn_action(){
fn_logecho "[INFO] Actual : Name: ${pidname}\tUser: ${piduser}\tPath: ${pidcommand}" fn_logecho "[INFO] Actual : Name: ${pidname}\tUser: ${piduser}\tPath: ${pidcommand}"
# Take the "before" action # Take the "before" action
fn_actionbefore fn_actionbefore
# Kill the app # If a before action has been done, refresh info
fn_logecho "[ACTION] Killing PID ${pid}" if [ -n "${refresh}" ]; then
kill -9 "${pid}" unset refresh
# Reset harm for future tests fn_define_vars
unset harm fn_evaluate
# Misc var to tell that an action has been taken fn_action
actiontaken="1"
# Misc var to count how many time we ran this
count=$((count+1))
# If $count is greater or equel to $maxruns; then end there
if [ "${count}" -ge "${maxruns}" ]; then
fn_logecho "[WARNING] Exiting because the loop has reached the maximum ${maxruns} runs"
fn_mail_alert
# Otherwise, let's run it again
else else
sleep "${sleeptime}" # Kill the app
fn_run_functions fn_logecho "[ACTION] Killing PID ${pid}"
kill -9 "${pid}"
# Reset harm for future tests
unset harm
# Misc var to count how many time we ran this
count=$((count+1))
# If $count is greater or equel to $maxruns; then end there
if [ "${count}" -ge "${maxruns}" ]; then
fn_logecho "[WARNING] Exiting because the loop has reached the maximum ${maxruns} runs"
fn_mail_alert
# Otherwise, let's run it again
else
sleep "${sleeptime}"
fn_run_functions
fi
fi fi
elif [ "${actiontaken}" == "1" ]; then elif [ "${actiontaken}" == "1" ]; then
fn_logecho "[OK] The process on port ${portcheck} now meets requirements" fn_logecho "[OK] The process on port ${portcheck} now meets requirements"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment