Skip to content

Commit

Permalink
fixed: GUI and other service restarts not always happening
Browse files Browse the repository at this point in the history
  • Loading branch information
kwindrem committed Jul 30, 2024
1 parent ce3247a commit 117dd17
Show file tree
Hide file tree
Showing 7 changed files with 1,774 additions and 49 deletions.
102 changes: 56 additions & 46 deletions HelperResources/CommonResources
Original file line number Diff line number Diff line change
Expand Up @@ -1030,11 +1030,13 @@ restartGuiV1Service ()
{
# gui is the older service that runs GUI v1 only
if [ -e "/service/gui" ]; then
logMessage "restarting GUI V1 (/service/gui)"
svc -t "/service/gui"
# restart GUI if NOT running v2 or can't determine if GUI v1 or v2 is selected
elif [ -e "/service/start-gui" ]; then
guiVersion="$(dbus-send --system --print-reply --dest=com.victronenergy.settings /Settings/Gui/RunningVersion com.victronenergy.BusItem.GetValue | grep variant | awk '{print $3}')"
local guiVersion="$(dbus-send --system --print-reply --dest=com.victronenergy.settings /Settings/Gui/RunningVersion com.victronenergy.BusItem.GetValue | grep variant | awk '{print $3}')"
if (( $guiVersion != 2 )); then
logMessage "restarting GUI V1 (/service/start-gui)"
svc -t "/service/start-gui"
fi
fi
Expand All @@ -1050,8 +1052,9 @@ restartGuiV2Service ()
{
# restart GUI if NOT running v1 or can't determine if GUI v1 or v2 is selected
if [ -e "/service/start-gui" ]; then
guiVersion="$(dbus-send --system --print-reply --dest=com.victronenergy.settings /Settings/Gui/RunningVersion com.victronenergy.BusItem.GetValue | grep variant | awk '{print $3}')"
local guiVersion="$(dbus-send --system --print-reply --dest=com.victronenergy.settings /Settings/Gui/RunningVersion com.victronenergy.BusItem.GetValue | grep variant | awk '{print $3}')"
if (( $guiVersion != 1 )); then
logMessage "restarting GUI V2 (/service/start-gui)"
svc -t "/service/start-gui"
fi
fi
Expand Down Expand Up @@ -1167,83 +1170,90 @@ endScript ()
exit $EXIT_SUCCESS
elif ! [ $scriptAction == 'INSTALL' ] && ! [ $scriptAction == 'UNINSTALL' ]; then
setInstallFailed $EXIT_ERROR "unexpected script action $scriptAction - did not install or uninstall"
exit $EXIT_ERROR
fi
fi

# check for reboot or restarts
# check for reboot and service restarts
if $rebootNeeded ; then
if $userInteraction ; then
if yesNoPrompt "Reboot system now (y) or do it manually later (n): " ; then
logMessage "rebooting ..."
reboot
deferReboot=false
else
logMessage "system must be rebooted to finish installation and activate components"
exit $EXIT_REBOOT
fi
else
logMessage "completed - reboot needed"
exit $EXIT_REBOOT
fi
fi
if $restartGeneratorService ; then
logMessage "restarting generator service"
svc -t /service/dbus-generator-starter
fi
if $restartSystemCalc ; then
logMessage "restarting systemcalc service"
svc -t /service/dbus-systemcalc-py
fi
if $restartDigitalinputs ; then
logMessage "restarting digital inputs service"
svc -t /service/dbus-digitalinputs

# restart services if a reboot won't happen below
if ! $rebootNeeded || $deferReboot ; then
if $restartGeneratorService ; then
logMessage "restarting generator service"
svc -t /service/dbus-generator-starter
fi
if $restartSystemCalc ; then
logMessage "restarting systemcalc service"
svc -t /service/dbus-systemcalc-py
fi
if $restartDigitalinputs ; then
logMessage "restarting digital inputs service"
svc -t /service/dbus-digitalinputs
fi
fi
#### TODO: add gui v2
if $restartGui ; then
if $userInteraction ; then
if yesNoPrompt "Restart the GUI now (y) or issue a do it manually later (n): " ; then
logMessage "completed - restarting GUI"
restartGuiV1Service
if $installFailed || $uninstallFailed ; then
exit $installExitReason
else
exit $EXIT_SUCCESS
fi
else
echo "GUI must be restarted to activate changes"
exit $EXIT_RESTART_GUI
deferGuiRestart=false
restartGui=ralse
fi
else
if $deferGuiRestart ; then
logMessage "completed - GUI restart needed"
exit $EXIT_RESTART_GUI
# GUI restart NOT deferred - do it now
else
logMessage "completed - restarting GUI"
if ! $deferGuiRestart ; then
restartGuiV1Service
if $installFailed || $uninstallFailed ; then
exit $installExitReason
else
exit $EXIT_SUCCESS
fi
deferGuiRestart=false
restartGui=ralse
fi
fi
fi

# if installation was attempted but failed, exit without checking anything else
local exitCode=$EXIT_SUCCESS
if $installFailed ; then
if [ $scriptAction == 'UNINSTALL' ]; then
logMessage "complete - package has been uninstalled"
if $uninstallFailed ; then
logMessage "CRITICAL: install failed with error $installExitReason"
logMessage "CRITICAL: uninstall also failed with error $uninstallExitReason - package state unknown"
exitCode=$uninstallExitReason
else
logMessage "install failed - package has been successfully uninstalled"
exitCode=$installExitReason
fi
else
logMessage "complete - no changes were made"
logMessage "install failed during prechecks - no changes were made"
exitCode=$installExitReason
fi
exit $installExitReason
# install/uninstall succeeded
elif $uninstallFailed ; then
logMessage "complete - uninstall failed !!"
logMessage "CRITICAL: uninstall failed - package state unknown"
exitCode=$installExitReason
elif $rebootNeeded ; then
if $deferReboot ; then
logMessage "reboot needed to complete operaiton"
exitCode=$EXIT_REBOOT
else
logMessage "rebooting ..."
reboot
fi
elif $restartGui && $deferGuiRestart ; then
echo "GUI must be restarted to activate changes"
exitCode=$EXIT_RESTART_GUI
# install/uninstall succeeded
else
logMessage "complete - no errors"
exit $EXIT_SUCCESS
exitCode=$EXIT_SUCCESS
fi

exit $exitCode
} # endScript ()

######## this code is executed in-line when CommonResources is sourced
Expand Down
Loading

0 comments on commit 117dd17

Please sign in to comment.