diff --git a/dev/debug_osync.sh b/dev/debug_osync.sh index dd426e2..b7499a9 100755 --- a/dev/debug_osync.sh +++ b/dev/debug_osync.sh @@ -44,7 +44,7 @@ IS_STABLE=no _OFUNCTIONS_VERSION=2.1.4-rc1+ -_OFUNCTIONS_BUILD=2017112301 +_OFUNCTIONS_BUILD=2017123001 _OFUNCTIONS_BOOTSTRAP=true ## BEGIN Generic bash functions written in 2013-2017 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr @@ -871,6 +871,7 @@ function ParallelExec { local noErrorLog="${10:-false}" # Log errors when reaching soft / hard max time (false), don't log errors on those triggers (true) local callerName="${FUNCNAME[1]}" + Logger "${FUNCNAME[0]} called by [${FUNCNAME[0]} < ${FUNCNAME[1]} < ${FUNCNAME[2]} < ${FUNCNAME[3]} < ${FUNCNAME[4]} ...]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG __CheckArguments 2-10 $# "$@" #__WITH_PARANOIA_DEBUG local log_ttime=0 # local time instance for comparaison @@ -928,7 +929,7 @@ function ParallelExec { if [ $((($exec_time + 1) % $keepLogging)) -eq 0 ]; then if [ $log_ttime -ne $exec_time ]; then # Fix when sleep time lower than 1s log_ttime=$exec_time - Logger "There are $((commandCount-counter-numberOfProcess)) / $commandCount in the task queue. Currently, $numberofProcess tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE" + Logger "There are $((commandCount-counter)) / $commandCount tasks in the queue. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE" fi fi fi @@ -1222,8 +1223,8 @@ function GetLocalOS { # Get linux versions if [ -f "/etc/os-release" ]; then - localOsName=$(GetConfFileValue "/etc/os-release" "NAME") - localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION") + localOsName=$(GetConfFileValue "/etc/os-release" "NAME" true) + localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION" true) fi # Add a global variable for statistics in installer @@ -1948,6 +1949,8 @@ function VerComp () { function GetConfFileValue () { local file="${1}" local name="${2}" + local noError="${3:-false}" + local value value=$(grep "^$name=" "$file") @@ -1955,10 +1958,15 @@ function GetConfFileValue () { value="${value##*=}" echo "$value" else - Logger "Cannot get value for [$name] in config file [$file]." "ERROR" + if [ $noError == true ]; then + Logger "Cannot get value for [$name] in config file [$file]." "NOTICE" + else + Logger "Cannot get value for [$name] in config file [$file]." "ERROR" + fi fi } + function SetConfFileValue () { local file="${1}" local name="${2}" diff --git a/dev/debug_osync_target_helper.sh b/dev/debug_osync_target_helper.sh index 3a2cad7..9560da8 100755 --- a/dev/debug_osync_target_helper.sh +++ b/dev/debug_osync_target_helper.sh @@ -8,8 +8,8 @@ PROGRAM_BUILD=2017061901 IS_STABLE=no -_OFUNCTIONS_VERSION=2.1.4-rc1 -_OFUNCTIONS_BUILD=2017060903 +_OFUNCTIONS_VERSION=2.1.4-rc1+ +_OFUNCTIONS_BUILD=2017123001 _OFUNCTIONS_BOOTSTRAP=true ## BEGIN Generic bash functions written in 2013-2017 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr @@ -23,6 +23,8 @@ _OFUNCTIONS_BOOTSTRAP=true ## _LOGGER_ERR_ONLY=true/false ## _LOGGER_PREFIX="date"/"time"/"" +#TODO: global WAIT_FOR_TASK_COMPLETION_id instead of callerName has to be backported to ParallelExec and osync / obackup / pmocr ocde + ## Logger sets {ERROR|WARN}_ALERT variable when called with critical / error / warn loglevel ## When called from subprocesses, variable of main process can't be set. Status needs to be get via $RUN_DIR/$PROGRAM.Logger.{error|warn}.$SCRIPT_PID.$TSTAMP @@ -318,7 +320,7 @@ function KillChilds { local self="${2:-false}" # Should parent be killed too ? # Paranoid checks, we can safely assume that $pid shouldn't be 0 nor 1 - if [ $(IsNumeric "$pid") -eq 0 ] || [ "$pid" == "" ] || [ "$pid" == "0" ] || [ "$pid" == "1" ]; then + if [ $(IsInteger "$pid") -eq 0 ] || [ "$pid" == "" ] || [ "$pid" == "0" ] || [ "$pid" == "1" ]; then Logger "Bogus pid given [$pid]." "CRITICAL" return 1 fi @@ -680,9 +682,10 @@ function WaitForTaskCompletion { local counting="${6:-true}" # Count time since function has been launched (true), or since script has been launched (false) local spinner="${7:-true}" # Show spinner (true), don't show anything (false) local noErrorLog="${8:-false}" # Log errors when reaching soft / hard max time (false), don't log errors on those triggers (true) + local id="${9-base}" # Optional id in order to get $WAIT_FOR_TASK_COMPLETION_id global variable local callerName="${FUNCNAME[1]}" - Logger "${FUNCNAME[0]} called by [$callerName]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG + Logger "${FUNCNAME[0]} called by [${FUNCNAME[0]} < ${FUNCNAME[1]} < ${FUNCNAME[2]} < ${FUNCNAME[3]} < ${FUNCNAME[4]} ...]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG __CheckArguments 8 $# "$@" #__WITH_PARANOIA_DEBUG local log_ttime=0 # local time instance for comparaison @@ -710,8 +713,8 @@ function WaitForTaskCompletion { pidCount=${#pidsArray[@]} # Set global var default - eval "WAIT_FOR_TASK_COMPLETION_$callerName=\"\"" - eval "HARD_MAX_EXEC_TIME_REACHED_$callerName=false" + eval "WAIT_FOR_TASK_COMPLETION_$id=\"\"" + eval "HARD_MAX_EXEC_TIME_REACHED_$id=false" while [ ${#pidsArray[@]} -gt 0 ]; do newPidsArray=() @@ -758,7 +761,7 @@ function WaitForTaskCompletion { if [ $noErrorLog != true ]; then SendAlert true fi - eval "HARD_MAX_EXEC_TIME_REACHED_$callerName=true" + eval "HARD_MAX_EXEC_TIME_REACHED_$id=true" return $errorcount fi @@ -778,10 +781,10 @@ function WaitForTaskCompletion { Logger "${FUNCNAME[0]} called by [$callerName] finished monitoring [$pid] with exitcode [$retval]." "DEBUG" errorcount=$((errorcount+1)) # Welcome to variable variable bash hell - if [ "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_$callerName\")" == "" ]; then - eval "WAIT_FOR_TASK_COMPLETION_$callerName=\"$pid:$retval\"" + if [ "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_$id\")" == "" ]; then + eval "WAIT_FOR_TASK_COMPLETION_$id=\"$pid:$retval\"" else - eval "WAIT_FOR_TASK_COMPLETION_$callerName=\";$pid:$retval\"" + eval "WAIT_FOR_TASK_COMPLETION_$id=\";$pid:$retval\"" fi fi fi @@ -833,6 +836,7 @@ function ParallelExec { local noErrorLog="${10:-false}" # Log errors when reaching soft / hard max time (false), don't log errors on those triggers (true) local callerName="${FUNCNAME[1]}" + Logger "${FUNCNAME[0]} called by [${FUNCNAME[0]} < ${FUNCNAME[1]} < ${FUNCNAME[2]} < ${FUNCNAME[3]} < ${FUNCNAME[4]} ...]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG __CheckArguments 2-10 $# "$@" #__WITH_PARANOIA_DEBUG local log_ttime=0 # local time instance for comparaison @@ -890,7 +894,7 @@ function ParallelExec { if [ $((($exec_time + 1) % $keepLogging)) -eq 0 ]; then if [ $log_ttime -ne $exec_time ]; then # Fix when sleep time lower than 1s log_ttime=$exec_time - Logger "Current tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE" + Logger "There are $((commandCount-counter)) / $commandCount tasks in the queue. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE" fi fi fi @@ -1184,8 +1188,8 @@ function GetLocalOS { # Get linux versions if [ -f "/etc/os-release" ]; then - localOsName=$(GetConfFileValue "/etc/os-release" "NAME") - localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION") + localOsName=$(GetConfFileValue "/etc/os-release" "NAME" true) + localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION" true) fi # Add a global variable for statistics in installer @@ -1910,6 +1914,8 @@ function VerComp () { function GetConfFileValue () { local file="${1}" local name="${2}" + local noError="${3:-false}" + local value value=$(grep "^$name=" "$file") @@ -1917,10 +1923,15 @@ function GetConfFileValue () { value="${value##*=}" echo "$value" else - Logger "Cannot get value for [$name] in config file [$file]." "ERROR" + if [ $noError == true ]; then + Logger "Cannot get value for [$name] in config file [$file]." "NOTICE" + else + Logger "Cannot get value for [$name] in config file [$file]." "ERROR" + fi fi } + function SetConfFileValue () { local file="${1}" local name="${2}" diff --git a/install.sh b/install.sh index a5365e1..af5b756 100755 --- a/install.sh +++ b/install.sh @@ -184,8 +184,8 @@ function GetLocalOS { # Get linux versions if [ -f "/etc/os-release" ]; then - localOsName=$(GetConfFileValue "/etc/os-release" "NAME") - localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION") + localOsName=$(GetConfFileValue "/etc/os-release" "NAME" true) + localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION" true) fi # Add a global variable for statistics in installer @@ -198,6 +198,8 @@ function GetLocalOS { function GetConfFileValue () { local file="${1}" local name="${2}" + local noError="${3:-false}" + local value value=$(grep "^$name=" "$file") @@ -205,10 +207,15 @@ function GetConfFileValue () { value="${value##*=}" echo "$value" else - Logger "Cannot get value for [$name] in config file [$file]." "ERROR" + if [ $noError == true ]; then + Logger "Cannot get value for [$name] in config file [$file]." "NOTICE" + else + Logger "Cannot get value for [$name] in config file [$file]." "ERROR" + fi fi } + function SetLocalOSSettings { USER=root diff --git a/osync.sh b/osync.sh index a1ebcf9..dce6062 100755 --- a/osync.sh +++ b/osync.sh @@ -15,7 +15,7 @@ IS_STABLE=no _OFUNCTIONS_VERSION=2.1.4-rc1+ -_OFUNCTIONS_BUILD=2017112301 +_OFUNCTIONS_BUILD=2017123001 _OFUNCTIONS_BOOTSTRAP=true ## BEGIN Generic bash functions written in 2013-2017 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr @@ -851,7 +851,7 @@ function ParallelExec { if [ $((($exec_time + 1) % $keepLogging)) -eq 0 ]; then if [ $log_ttime -ne $exec_time ]; then # Fix when sleep time lower than 1s log_ttime=$exec_time - Logger "There are $((commandCount-counter-numberOfProcess)) / $commandCount in the task queue. Currently, $numberofProcess tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE" + Logger "There are $((commandCount-counter)) / $commandCount tasks in the queue. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE" fi fi fi @@ -1137,8 +1137,8 @@ function GetLocalOS { # Get linux versions if [ -f "/etc/os-release" ]; then - localOsName=$(GetConfFileValue "/etc/os-release" "NAME") - localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION") + localOsName=$(GetConfFileValue "/etc/os-release" "NAME" true) + localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION" true) fi # Add a global variable for statistics in installer @@ -1790,6 +1790,8 @@ function VerComp () { function GetConfFileValue () { local file="${1}" local name="${2}" + local noError="${3:-false}" + local value value=$(grep "^$name=" "$file") @@ -1797,10 +1799,15 @@ function GetConfFileValue () { value="${value##*=}" echo "$value" else - Logger "Cannot get value for [$name] in config file [$file]." "ERROR" + if [ $noError == true ]; then + Logger "Cannot get value for [$name] in config file [$file]." "NOTICE" + else + Logger "Cannot get value for [$name] in config file [$file]." "ERROR" + fi fi } + function SetConfFileValue () { local file="${1}" local name="${2}" diff --git a/osync_target_helper.sh b/osync_target_helper.sh index a045976..a1daef5 100755 --- a/osync_target_helper.sh +++ b/osync_target_helper.sh @@ -8,8 +8,8 @@ PROGRAM_BUILD=2017061901 IS_STABLE=no -_OFUNCTIONS_VERSION=2.1.4-rc1 -_OFUNCTIONS_BUILD=2017060903 +_OFUNCTIONS_VERSION=2.1.4-rc1+ +_OFUNCTIONS_BUILD=2017123001 _OFUNCTIONS_BOOTSTRAP=true ## BEGIN Generic bash functions written in 2013-2017 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr @@ -23,6 +23,8 @@ _OFUNCTIONS_BOOTSTRAP=true ## _LOGGER_ERR_ONLY=true/false ## _LOGGER_PREFIX="date"/"time"/"" +#TODO: global WAIT_FOR_TASK_COMPLETION_id instead of callerName has to be backported to ParallelExec and osync / obackup / pmocr ocde + ## Logger sets {ERROR|WARN}_ALERT variable when called with critical / error / warn loglevel ## When called from subprocesses, variable of main process can't be set. Status needs to be get via $RUN_DIR/$PROGRAM.Logger.{error|warn}.$SCRIPT_PID.$TSTAMP @@ -303,7 +305,7 @@ function KillChilds { local self="${2:-false}" # Should parent be killed too ? # Paranoid checks, we can safely assume that $pid shouldn't be 0 nor 1 - if [ $(IsNumeric "$pid") -eq 0 ] || [ "$pid" == "" ] || [ "$pid" == "0" ] || [ "$pid" == "1" ]; then + if [ $(IsInteger "$pid") -eq 0 ] || [ "$pid" == "" ] || [ "$pid" == "0" ] || [ "$pid" == "1" ]; then Logger "Bogus pid given [$pid]." "CRITICAL" return 1 fi @@ -645,6 +647,7 @@ function WaitForTaskCompletion { local counting="${6:-true}" # Count time since function has been launched (true), or since script has been launched (false) local spinner="${7:-true}" # Show spinner (true), don't show anything (false) local noErrorLog="${8:-false}" # Log errors when reaching soft / hard max time (false), don't log errors on those triggers (true) + local id="${9-base}" # Optional id in order to get $WAIT_FOR_TASK_COMPLETION_id global variable local callerName="${FUNCNAME[1]}" @@ -672,8 +675,8 @@ function WaitForTaskCompletion { pidCount=${#pidsArray[@]} # Set global var default - eval "WAIT_FOR_TASK_COMPLETION_$callerName=\"\"" - eval "HARD_MAX_EXEC_TIME_REACHED_$callerName=false" + eval "WAIT_FOR_TASK_COMPLETION_$id=\"\"" + eval "HARD_MAX_EXEC_TIME_REACHED_$id=false" while [ ${#pidsArray[@]} -gt 0 ]; do newPidsArray=() @@ -720,7 +723,7 @@ function WaitForTaskCompletion { if [ $noErrorLog != true ]; then SendAlert true fi - eval "HARD_MAX_EXEC_TIME_REACHED_$callerName=true" + eval "HARD_MAX_EXEC_TIME_REACHED_$id=true" return $errorcount fi @@ -740,10 +743,10 @@ function WaitForTaskCompletion { Logger "${FUNCNAME[0]} called by [$callerName] finished monitoring [$pid] with exitcode [$retval]." "DEBUG" errorcount=$((errorcount+1)) # Welcome to variable variable bash hell - if [ "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_$callerName\")" == "" ]; then - eval "WAIT_FOR_TASK_COMPLETION_$callerName=\"$pid:$retval\"" + if [ "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_$id\")" == "" ]; then + eval "WAIT_FOR_TASK_COMPLETION_$id=\"$pid:$retval\"" else - eval "WAIT_FOR_TASK_COMPLETION_$callerName=\";$pid:$retval\"" + eval "WAIT_FOR_TASK_COMPLETION_$id=\";$pid:$retval\"" fi fi fi @@ -842,7 +845,7 @@ function ParallelExec { if [ $((($exec_time + 1) % $keepLogging)) -eq 0 ]; then if [ $log_ttime -ne $exec_time ]; then # Fix when sleep time lower than 1s log_ttime=$exec_time - Logger "Current tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE" + Logger "There are $((commandCount-counter)) / $commandCount tasks in the queue. Currently, ${#pidsArray[@]} tasks running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE" fi fi fi @@ -1128,8 +1131,8 @@ function GetLocalOS { # Get linux versions if [ -f "/etc/os-release" ]; then - localOsName=$(GetConfFileValue "/etc/os-release" "NAME") - localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION") + localOsName=$(GetConfFileValue "/etc/os-release" "NAME" true) + localOsVer=$(GetConfFileValue "/etc/os-release" "VERSION" true) fi # Add a global variable for statistics in installer @@ -1781,6 +1784,8 @@ function VerComp () { function GetConfFileValue () { local file="${1}" local name="${2}" + local noError="${3:-false}" + local value value=$(grep "^$name=" "$file") @@ -1788,10 +1793,15 @@ function GetConfFileValue () { value="${value##*=}" echo "$value" else - Logger "Cannot get value for [$name] in config file [$file]." "ERROR" + if [ $noError == true ]; then + Logger "Cannot get value for [$name] in config file [$file]." "NOTICE" + else + Logger "Cannot get value for [$name] in config file [$file]." "ERROR" + fi fi } + function SetConfFileValue () { local file="${1}" local name="${2}"