Skip to content

Commit

Permalink
v7.8
Browse files Browse the repository at this point in the history
+ DietPi-Services | When printing the status, instead of removing a hardcoded number of 11 characters from the start of the line, remove the first field and delimiter. The number of leading spaces has changed with Bullseye, so that the colon of "Active:" was shown unintentionally.
  • Loading branch information
MichaIng committed Nov 6, 2021
1 parent c211e5c commit 4664307
Showing 1 changed file with 1 addition and 47 deletions.
48 changes: 1 addition & 47 deletions dietpi/dietpi-services
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ _EOF_

while read -r line
do

# Include
if [[ $line == '+ '* ]]; then

Expand All @@ -285,9 +284,7 @@ _EOF_
# - Skip known services
for i in "${aSERVICE_NAME[@]}"
do

[[ $line == "$i" ]] && continue 2

done

[[ $G_DEBUG == 1 ]] && G_DIETPI-NOTIFY 2 "Including custom service: $line"
Expand All @@ -300,7 +297,6 @@ _EOF_

for i in "${!aSERVICE_NAME[@]}"
do

[[ $line == "${aSERVICE_NAME[$i]}" ]] || continue

# Show in menu, but mark as excluded
Expand All @@ -316,7 +312,6 @@ _EOF_
fi

break

done

fi
Expand All @@ -340,26 +335,22 @@ _EOF_
local i j
for i in "${!aSERVICE_NAME[@]}"
do

[[ ${aSERVICE_NAME[$i]} ]] || { unset -v "aSERVICE_NAME[$i]"; continue; } # Failsafe

# Check for sysvinit services from systemd-sysv-generator dir: /run/systemd/generator.late/
for j in /{{etc,usr/local/lib,lib,usr/lib}/systemd/system,run/systemd/generator.late}/"${aSERVICE_NAME[$i]}.service"
do

[[ -e $j ]] || continue

# Check masked state, in case continue to catch real file
[[ -L $j && $(readlink -m "$j") == '/dev/null' ]] && aSERVICE_MODE[$i]='masked' && continue

aFP_SERVICE[$i]=$j
break

done

# Remove non-available services from array
[[ ${aFP_SERVICE[$i]} ]] || unset -v "aSERVICE_NAME[$i]"

done

}
Expand Down Expand Up @@ -388,9 +379,7 @@ _EOF_

for i in "${!aSERVICE_NAME[@]}"
do

services="$i $services"

done

# - start/restart: Standard service order
Expand All @@ -411,12 +400,10 @@ _EOF_
# Apply command
for i in $services
do

[[ ${aSERVICE_MODE[$i]} == 'masked' ]] && { G_DIETPI-NOTIFY 2 "skip : ${aSERVICE_NAME[$i]} (due to mask)"; continue; }
G_DIETPI-NOTIFY -2 "${aSERVICE_NAME[$i]}"
systemctl "$command" "${aSERVICE_NAME[$i]}" &> /dev/null
Print_Status "$command" "${aSERVICE_NAME[$i]}" $?

done

# Disable ownCloud and Nextcloud maintenance mode after all services being started or restarted
Expand Down Expand Up @@ -450,12 +437,11 @@ _EOF_
local status_full space status
for i in $services
do

status_full=$(systemctl -l --no-pager status "${aSERVICE_NAME[$i]}")
# Align status output
space='\t'
(( ${#aSERVICE_NAME[$i]} < 13 )) && space+='\t'; (( ${#aSERVICE_NAME[$i]} < 5 )) && space+='\t'
status="${aSERVICE_NAME[$i]}${space}$(mawk '/Active/{print substr($0,12);exit}' <<< "$status_full")"
status="${aSERVICE_NAME[$i]}${space}$(mawk '/Active:/{$1="";print;exit}' <<< "$status_full")"; status=${status# }
if [[ $status == *'failed'* ]]; then

G_DIETPI-NOTIFY 1 "$status_full"
Expand All @@ -469,7 +455,6 @@ _EOF_
G_DIETPI-NOTIFY 0 "$status"

fi

done

# dietpi_controlled/systemd_controlled/mask/unmask/enable/disable
Expand Down Expand Up @@ -505,12 +490,10 @@ _EOF_
# Apply command
for i in $services
do

# Skip masked services, if not to be unmasked
[[ ${aSERVICE_MODE[$i]} == 'masked' && $systemctl_cmd != 'unmask' ]] && { G_DIETPI-NOTIFY 2 "skip : ${aSERVICE_NAME[$i]} (due to mask)"; continue; }
systemctl $systemctl_cmd "${aSERVICE_NAME[$i]}" &> /dev/null
Print_Status "$command" "${aSERVICE_NAME[$i]}" $?

done

fi
Expand Down Expand Up @@ -621,10 +604,8 @@ _EOF_

for i in "${!aSERVICE_NAME[@]}"
do

aSERVICE_MODE[$i]=$(systemctl is-enabled "${aSERVICE_NAME[$i]}" 2> /dev/null)
Load_Process_Tool "$i"

done

}
Expand All @@ -649,7 +630,6 @@ _EOF_
local service_restart_list_menu aservice_restart_list_systemd=() i
for i in "${!aSERVICE_RESTART_REQUIRED[@]}"
do

service_restart_list_menu+="\n - ${aSERVICE_NAME[$i]}: "
[[ ${aCPU_AFFINITY[$i]} ]] && service_restart_list_menu+="Affinity=${aCPU_AFFINITY[$i]} | "
[[ ${aCPU_POLICY[$i]} ]] && service_restart_list_menu+="CPU Scheduling Policy=${aCPU_POLICY[$i]} | "
Expand All @@ -658,7 +638,6 @@ _EOF_
[[ ${aIO_CLASS[$i]} ]] && service_restart_list_menu+="I/O Scheduling Class=${aIO_CLASS[$i]} | "
[[ ${aIO_PRIORITY[$i]} ]] && service_restart_list_menu+="I/O Scheduling Priority=${aIO_PRIORITY[$i]} | "
aservice_restart_list_systemd+=("${aSERVICE_NAME[$i]}")

done

if [[ ${aservice_restart_list_systemd[0]} ]] && G_WHIP_YESNO "[ INFO ] The following services require a restart, in order to apply your chosen settings:${service_restart_list_menu%[|:] }
Expand Down Expand Up @@ -686,9 +665,7 @@ _EOF_
G_WHIP_MENU_ARRAY=('' '●─ Single Service Options ')
for i in "${!aSERVICE_NAME[@]}"
do

G_WHIP_MENU_ARRAY+=("${aSERVICE_NAME[$i]}" ": $(systemctl is-active "${aSERVICE_NAME[$i]}") | Affinity ${aCPU_AFFINITY[$i]:-0-$(( $G_HW_CPU_CORES - 1 ))}")

done
G_WHIP_MENU_ARRAY+=(

Expand All @@ -711,29 +688,23 @@ _EOF_
# Find first empty index
for ((i=0;i<=${#aSERVICE_MODE[@]};i++))
do

[[ ${aSERVICE_NAME[$i]} ]] || { new_index=$i; break; }

done
while G_WHIP_INPUTBOX "${not_found}Please add the name of the service to be added, without the \".service\" file ending:"
do

if [[ $G_WHIP_RETURNED_VALUE ]]; then

# Check for known services
for i in "${aSERVICE_NAME[@]}"
do

[[ $G_WHIP_RETURNED_VALUE == "$i" ]] || continue

not_found="[FAILED] The service name you entered ($G_WHIP_RETURNED_VALUE) is already handled by DietPi-Services. Please retry or cancel.\n\n"
continue 2

done

for i in /{{etc,usr/local/lib,lib,usr/lib}/systemd/system,run/systemd/generator.late}/"$G_WHIP_RETURNED_VALUE.service"
do

[[ -f $i ]] || continue

aSERVICE_NAME[$new_index]=$G_WHIP_RETURNED_VALUE
Expand All @@ -742,13 +713,11 @@ _EOF_
Load_Process_Tool "$new_index"
G_CONFIG_INJECT "+ ${aSERVICE_NAME[$new_index]}" "+ ${aSERVICE_NAME[$new_index]}" $FP_INCLUDE_EXCLUDE
break 2

done

fi

not_found="[FAILED] Could not find a service file that matches your input ($G_WHIP_RETURNED_VALUE). Please retry or cancel.\n\n"

done

elif [[ $G_WHIP_RETURNED_VALUE == 'Restart' || $G_WHIP_RETURNED_VALUE == 'Stop' ]]; then
Expand All @@ -764,11 +733,9 @@ _EOF_
MENU_SERVICE_INDEX=-1
for i in "${!aSERVICE_NAME[@]}"
do

[[ ${aSERVICE_NAME[$i]} == "$G_WHIP_RETURNED_VALUE" ]] || continue
MENU_SERVICE_INDEX=$i
break

done
(( $MENU_SERVICE_INDEX >= 0 )) && MENU_TARGETID=1

Expand Down Expand Up @@ -975,9 +942,7 @@ Please uncomment and edit only the lines that you need to change.\n\nTo undo cha
G_WHIP_CHECKLIST_ARRAY=()
for ((i=0; i<$G_HW_CPU_CORES; i++))
do

G_WHIP_CHECKLIST_ARRAY+=("$i" 'CPU ' 'on')

done

if G_WHIP_CHECKLIST "Please select the desired CPU Affinity for: ${aSERVICE_NAME[$MENU_SERVICE_INDEX]}\n
Expand All @@ -986,10 +951,8 @@ Please uncomment and edit only the lines that you need to change.\n\nTo undo cha
local new_affinity=
for i in $G_WHIP_RETURNED_VALUE
do

# taskset requires comma-seperated CPU indices
[[ $new_affinity ]] && new_affinity+=",$i" || new_affinity=$i

done

# Update affinity array with new value, if at least 1 item was selected, otherwise reset
Expand All @@ -1004,9 +967,7 @@ Please uncomment and edit only the lines that you need to change.\n\nTo undo cha
G_WHIP_MENU_ARRAY=('Reset' ': Reset CPU Scheduling Policy to system defaults')
for i in "${!aCPU_POLICY_TYPE[@]}"
do

G_WHIP_MENU_ARRAY+=("${aCPU_POLICY_TYPE[$i]}" ": ${aCPU_POLICY_DESC[$i]}" )

done

G_WHIP_DEFAULT_ITEM=$cpu_policy
Expand Down Expand Up @@ -1087,7 +1048,6 @@ Info:\n - Negative values have a higher priority (eg: -10).\n - Positive values
G_WHIP_MENU_ARRAY=('Reset' ': Reset CPU Scheduling Priority to system defaults')
for ((i=$scale_value_highest; i>=$scale_value_lowest; i--))
do

if (( $i == $scale_value_lowest )); then

desc='(Lowest priority)'
Expand Down Expand Up @@ -1123,7 +1083,6 @@ Info:\n - Negative values have a higher priority (eg: -10).\n - Positive values
fi

G_WHIP_MENU_ARRAY+=("$i" ": $desc")

done

G_WHIP_DEFAULT_ITEM=$cpu_priority
Expand All @@ -1141,9 +1100,7 @@ Info:\n - Negative values have a higher priority (eg: -10).\n - Positive values
G_WHIP_MENU_ARRAY=('Reset' ': Reset I/O Scheduling Class to system defaults')
for i in "${!aIO_CLASS_TYPE[@]}"
do

G_WHIP_MENU_ARRAY+=("${aIO_CLASS_TYPE[$i]}" ": ${aIO_CLASS_DESC[$i]}" )

done

G_WHIP_DEFAULT_ITEM=$io_class
Expand Down Expand Up @@ -1180,7 +1137,6 @@ NB: This only has an effect on drives handled by the CFQ scheduler.\nRead about
fi

G_WHIP_MENU_ARRAY+=("$i" ": $desc")

done

G_WHIP_DEFAULT_ITEM=$io_priority
Expand Down Expand Up @@ -1264,7 +1220,6 @@ NB: This only has an effect on drives handled by the CFQ scheduler."; then

until (( $MENU_TARGETID < 0 ))
do

if (( $MENU_TARGETID == 1 )); then

Menu_Service
Expand All @@ -1274,7 +1229,6 @@ NB: This only has an effect on drives handled by the CFQ scheduler."; then
Menu_Main

fi

done

fi
Expand Down

0 comments on commit 4664307

Please sign in to comment.