-
Notifications
You must be signed in to change notification settings - Fork 102
feat(power): configurable power button behavior + rename Power Mode → Power Options (OS-463) #2671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3b2d096
70281a7
c4fa856
1e7413b
f7d5646
1bc8a52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| Menu="PowerMode:2" | ||
| Title="Power Button" | ||
| Tag="icon-power" | ||
| --- | ||
| <?PHP | ||
| /* Copyright 2005-2025, Lime Technology | ||
| * Copyright 2012-2025, Bergware International. | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| */ | ||
| ?> | ||
| <? | ||
| $cur = _var($powermode,'powerbutton','shutdown'); | ||
| ?> | ||
|
|
||
| <form markdown="1" name="PowerButton" method="POST" action="/update.php" target="progressFrame"> | ||
| <input type="hidden" name="#file" value="dynamix/dynamix.cfg"> | ||
| <input type="hidden" name="#section" value="powermode"> | ||
|
|
||
| _(Physical power button)_: | ||
| : <select name="powerbutton" id="powerbutton" onchange="powerbuttonExtra(this)"> | ||
| <?=mk_option($cur, "shutdown", _('Shut down').' ('._('default').')')?> | ||
| <?=mk_option($cur, "reboot", _('Reboot'))?> | ||
| <?=mk_option($cur, "ignore", _('Do nothing'))?> | ||
| <?php | ||
| // Extension point: plugins add <option> lines for custom actions. | ||
| // In scope: $cur (current powerbutton value). See /etc/acpi/powerbutton.d/README. | ||
| foreach (glob('/usr/local/emhttp/plugins/*/include/powerbutton-option.php') ?: [] as $frag) include $frag; | ||
| ?> | ||
| </select> | ||
|
|
||
| :powerbutton_behavior_help: | ||
|
|
||
| <?php | ||
| // Extension point: plugins add config rows shown when their action is selected. | ||
| // Each fragment outputs: <div class="powerbutton-extra" data-action="<action>" markdown="1"> ...fields... </div> | ||
| foreach (glob('/usr/local/emhttp/plugins/*/include/powerbutton-extra.php') ?: [] as $frag) include $frag; | ||
| ?> | ||
|
|
||
| | ||
| : <span class="inline-block"> | ||
| <input type="submit" name="#apply" value="_(Apply)_" disabled> | ||
| <input type="button" value="_(Done)_" onclick="done()"> | ||
| </span> | ||
| </form> | ||
|
|
||
| <script> | ||
| function powerbuttonExtra(sel) { | ||
| var v = sel.value; | ||
| $('.powerbutton-extra').each(function(){ | ||
| $(this).toggle($(this).data('action') === v); | ||
| }); | ||
| } | ||
| $(function(){ powerbuttonExtra(document.getElementById('powerbutton')); }); | ||
| </script> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,77 +1,5 @@ | ||
| Menu="OtherSettings" | ||
| Type="xmenu" | ||
| Title="Power Mode" | ||
| Title="Power Options" | ||
| Tabs="true" | ||
| Icon="icon-energysaving" | ||
| Tag="icon-energysaving" | ||
| --- | ||
| <?PHP | ||
| /* Copyright 2005-2023, Lime Technology | ||
| * Copyright 2012-2023, Bergware International. | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| */ | ||
| ?> | ||
| <? | ||
| $cpufreq = '/sys/devices/system/cpu/cpu0/cpufreq'; | ||
| $current = exec("cat $cpufreq/scaling_governor 2>/dev/null"); | ||
| exec("cat $cpufreq/scaling_available_governors 2>/dev/null | tr ' ' '\n' | sed '/^$/d' | sort -u",$governor); | ||
|
|
||
| function value(...$modes) { | ||
| global $current, $governor; | ||
| $checked = $value = ''; | ||
| $disabled = ' disabled'; | ||
| foreach ($modes as $mode) { | ||
| if ($mode==$current) $checked = ' checked'; | ||
| if (in_array($mode,$governor)) {$value = "value=\"$mode\""; $disabled = '';} | ||
| } | ||
| return $value.$checked.$disabled; | ||
| } | ||
| ?> | ||
| <script> | ||
| function preparePowermode(form) { | ||
| $(form).find('[name="#arg[1]"]').val(form.powermode.value); | ||
| } | ||
| $(function(){ | ||
| $('input[type=radio]').each(function(){ | ||
| if ($(this).prop('disabled')) $(this).next('span').html(" <i>(_(unavailable)_)</i>"); | ||
| }); | ||
| <?if (exec("dmesg | grep -Pom1 'Hypervisor detected'")):?> | ||
| $('#vm').show(); | ||
| <?endif;?> | ||
| }); | ||
| </script> | ||
|
|
||
| <form markdown="1" name="PowerMode" method="POST" action="/update.php" target="progressFrame" onsubmit="preparePowermode(this)"> | ||
| <input type="hidden" name="#file" value="dynamix/dynamix.cfg"> | ||
| <input type="hidden" name="#section" value="powermode"> | ||
| <input type="hidden" name="#command" value="/webGui/scripts/powermode"> | ||
| <input type="hidden" name="#arg[1]" value=""> | ||
|
|
||
| _(Change power mode)_: | ||
| : <span> | ||
| <input name="powermode" type="radio"<?=value('powersave')?>>_(Best power efficiency)_ | ||
| </span> | ||
|
|
||
| | ||
| : <span> | ||
| <input name="powermode" type="radio"<?=value('ondemand','balance_power')?>>_(Balanced operation)_ | ||
| </span> | ||
|
|
||
| | ||
| : <span> | ||
| <input name="powermode" type="radio"<?=value('performance')?>>_(Best performance)_ | ||
| </span> | ||
|
|
||
| | ||
| : <span class="inline-block"> | ||
| <input type="submit" name="#apply" value="_(Apply)_" disabled> | ||
| <input type="button" value="_(Done)_" onclick="done()"> | ||
| </span> | ||
| </form> | ||
|
|
||
| <div id="vm" class="notice">_(When running Unraid virtualized, there are no available power modes)_</div> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||||||||||||
| Menu="PowerMode:1" | ||||||||||||||||||||||
| Title="Power Mode" | ||||||||||||||||||||||
| Tag="icon-energysaving" | ||||||||||||||||||||||
| --- | ||||||||||||||||||||||
| <?PHP | ||||||||||||||||||||||
| /* Copyright 2005-2023, Lime Technology | ||||||||||||||||||||||
| * Copyright 2012-2023, Bergware International. | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * This program is free software; you can redistribute it and/or | ||||||||||||||||||||||
| * modify it under the terms of the GNU General Public License version 2, | ||||||||||||||||||||||
| * as published by the Free Software Foundation. | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * The above copyright notice and this permission notice shall be included in | ||||||||||||||||||||||
| * all copies or substantial portions of the Software. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| ?> | ||||||||||||||||||||||
| <? | ||||||||||||||||||||||
| $cpufreq = '/sys/devices/system/cpu/cpu0/cpufreq'; | ||||||||||||||||||||||
| $current = exec("cat $cpufreq/scaling_governor 2>/dev/null"); | ||||||||||||||||||||||
| exec("cat $cpufreq/scaling_available_governors 2>/dev/null | tr ' ' '\n' | sed '/^$/d' | sort -u",$governor); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function value(...$modes) { | ||||||||||||||||||||||
| global $current, $governor; | ||||||||||||||||||||||
| $checked = $value = ''; | ||||||||||||||||||||||
| $disabled = ' disabled'; | ||||||||||||||||||||||
| foreach ($modes as $mode) { | ||||||||||||||||||||||
| if ($mode==$current) $checked = ' checked'; | ||||||||||||||||||||||
| if (in_array($mode,$governor)) {$value = "value=\"$mode\""; $disabled = '';} | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return $value.$checked.$disabled; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ?> | ||||||||||||||||||||||
| <script> | ||||||||||||||||||||||
| function preparePowermode(form) { | ||||||||||||||||||||||
| $(form).find('[name="#arg[1]"]').val(form.powermode.value); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| $(function(){ | ||||||||||||||||||||||
| $('input[type=radio]').each(function(){ | ||||||||||||||||||||||
| if ($(this).prop('disabled')) $(this).next('span').html(" <i>(_(unavailable)_)</i>"); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
Comment on lines
+38
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unavailable-label injection currently never matches the DOM. At Line 39, Suggested fix $(function(){
$('input[type=radio]').each(function(){
- if ($(this).prop('disabled')) $(this).next('span').html(" <i>(_(unavailable)_)</i>");
+ if ($(this).prop('disabled')) {
+ $(this).after(" <i>(_(unavailable)_)</i>");
+ }
});
<?if (exec("dmesg | grep -Pom1 'Hypervisor detected'")):?>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| <?if (exec("dmesg | grep -Pom1 'Hypervisor detected'")):?> | ||||||||||||||||||||||
| $('#vm').show(); | ||||||||||||||||||||||
| <?endif;?> | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| </script> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| <form markdown="1" name="PowerMode" method="POST" action="/update.php" target="progressFrame" onsubmit="preparePowermode(this)"> | ||||||||||||||||||||||
| <input type="hidden" name="#file" value="dynamix/dynamix.cfg"> | ||||||||||||||||||||||
| <input type="hidden" name="#section" value="powermode"> | ||||||||||||||||||||||
| <input type="hidden" name="#command" value="/webGui/scripts/powermode"> | ||||||||||||||||||||||
| <input type="hidden" name="#arg[1]" value=""> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| _(Change power mode)_: | ||||||||||||||||||||||
| : <span> | ||||||||||||||||||||||
| <input name="powermode" type="radio"<?=value('powersave')?>>_(Best power efficiency)_ | ||||||||||||||||||||||
| </span> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| | ||||||||||||||||||||||
| : <span> | ||||||||||||||||||||||
| <input name="powermode" type="radio"<?=value('ondemand','balance_power')?>>_(Balanced operation)_ | ||||||||||||||||||||||
| </span> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| | ||||||||||||||||||||||
| : <span> | ||||||||||||||||||||||
| <input name="powermode" type="radio"<?=value('performance')?>>_(Best performance)_ | ||||||||||||||||||||||
| </span> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| | ||||||||||||||||||||||
| : <span class="inline-block"> | ||||||||||||||||||||||
| <input type="submit" name="#apply" value="_(Apply)_" disabled> | ||||||||||||||||||||||
| <input type="button" value="_(Done)_" onclick="done()"> | ||||||||||||||||||||||
| </span> | ||||||||||||||||||||||
| </form> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| <div id="vm" class="notice" style="height:auto;min-height:6rem;line-height:2.4rem;padding-top:1.8rem;padding-bottom:1.8rem">_(When running Unraid virtualized, there are no available power modes)_</div> | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /etc/acpi/powerbutton.d/ - Unraid power button action handlers (extension point) | ||
| ================================================================================ | ||
|
|
||
| The physical power button behavior is configured in the WebUI at | ||
| Settings > Power Options > Power Button. The selected action is stored as | ||
| [powermode] | ||
| powerbutton="<action>" | ||
| in /boot/config/plugins/dynamix/dynamix.cfg and dispatched at press time by | ||
| /etc/acpi/unraid_power_handler.sh. | ||
|
|
||
| Built-in actions: shutdown (default), reboot, ignore. | ||
|
|
||
| Actions that need their own setup or prep (suspend/sleep, running a User | ||
| Script, etc.) are NOT built in - they are provided by plugins through the | ||
| two-part hook below, so core stays free of plugin-specific or hardware-risky | ||
| behavior. | ||
|
|
||
| Plugins can ADD or OVERRIDE actions in two parts: | ||
|
|
||
| 1) Action handler (required) | ||
| Ship an executable here, named after the action value: | ||
| /etc/acpi/powerbutton.d/<action> | ||
| It runs when the power button is pressed and that action is selected. | ||
| (e.g. the S3 Sleep plugin ships powerbutton.d/sleep to suspend with its | ||
| own array-aware prep.) | ||
|
|
||
| 2) WebUI option (so users can pick it) | ||
| Add the action to the selector by shipping: | ||
| /usr/local/emhttp/plugins/<plugin>/include/powerbutton-option.php | ||
| which echoes one or more options, e.g.: | ||
| <?=mk_option($cur, "script", _('Run script'))?> | ||
| ($cur is the currently saved powerbutton value.) | ||
|
|
||
| For extra fields shown only when your action is selected, also ship: | ||
| /usr/local/emhttp/plugins/<plugin>/include/powerbutton-extra.php | ||
| which outputs a block tagged with your action value: | ||
| <div class="powerbutton-extra" data-action="script" markdown="1"> | ||
| _(Script)_: | ||
| : <select name="powerbuttonscript"> ... </select> | ||
| </div> | ||
| Fields are POSTed into dynamix.cfg [powermode] alongside powerbutton, so | ||
| your handler can read them with the same grep pattern used above. | ||
|
|
||
| Example (User Scripts plugin, "Run script" action): | ||
| - include/powerbutton-option.php : adds the "script" option + script picker | ||
| - include/powerbutton-extra.php : script selection dropdown | ||
| - /etc/acpi/powerbutton.d/script : reads powerbuttonscript= from dynamix.cfg | ||
| and executes the chosen user script |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,78 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # script: unraid_power_handler.sh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Unraid ACPI event handler. Installed over /etc/acpi/acpi_handler.sh at boot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # by /etc/rc.d/rc.acpid, so it reliably overrides the stock Slackware acpid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # handler regardless of package install order. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # The physical power button behavior is configurable from the WebUI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # (Settings > Power Options > Power Button). The choice is stored in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # dynamix.cfg and read live on each event, so no acpid reload is needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # when the setting changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Plugins can add or override actions by dropping an executable handler in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # /etc/acpi/powerbutton.d/<action> - see /etc/acpi/powerbutton.d/README. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # LimeTech - modified for Unraid OS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CFG=/boot/config/plugins/dynamix/dynamix.cfg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PLUGIN_DIR=/etc/acpi/powerbutton.d | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # acpid passes the raw event line, e.g.: "button/power PBTN 00000080 00000000" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -- $@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group=${1%%/*} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action=${1#*/} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run_powerbutton(){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local behavior=$1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "$behavior" in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ignore) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger -t acpid "Power button: ignored (Power Options setting)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reboot) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger -t acpid "Power button: rebooting" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /sbin/init 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shutdown) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger -t acpid "Power button: initiating clean shutdown" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /sbin/init 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Extension point: plugin-provided action handler. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -n $behavior && -x $PLUGIN_DIR/$behavior ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger -t acpid "Power button: running plugin action '$behavior'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "$PLUGIN_DIR/$behavior" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger -t acpid "Power button: unknown action '$behavior', ignoring" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Unexpected config values don't fall back to shutdown, contradicting the documented default. The PR spec states the power button "defaults to shutdown for unset or unexpected values," but this code only defaults to shutdown when 🔧 Proposed fix else
- logger -t acpid "Power button: unknown action '$behavior', ignoring"
+ logger -t acpid "Power button: unknown action '$behavior', defaulting to shutdown"
+ /sbin/init 0
fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents🔒 Security & Privacy | 🟠 Major | ⚡ Quick win Unsanitized config value used as a path component enables path traversal.
🔒 Proposed fix *)
# Extension point: plugin-provided action handler.
- if [[ -n $behavior && -x $PLUGIN_DIR/$behavior ]]; then
+ if [[ -n $behavior && $behavior != */* && -x $PLUGIN_DIR/$behavior ]]; then📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "$group" in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| button) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "$action" in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| power) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Debounce: some boards/acpid setups deliver the same power-button event | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # more than once in quick succession, which would log (and act on) it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # twice. Ignore a repeat within 1 second of the previous press. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| STAMP=/run/unraid_powerbutton.stamp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| now=$(date +%s%N) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| last=$(cat "$STAMP" 2>/dev/null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "$now" >"$STAMP" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -n $last && $(( (now - last) / 1000000 )) -lt 1000 ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| behavior=$(grep -Pom1 '^powerbutton="\K[^"]+' "$CFG" 2>/dev/null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run_powerbutton "${behavior:-shutdown}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger -t acpid "ACPI action button/$action is not handled" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger -t acpid "ACPI event $1 is not handled" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
does restarting elogind service terminate active login sessions💡 Result:
Yes, restarting the elogind service typically causes the loss of all existing login sessions [1]. Elogind acts as a system daemon that manages user logins, tracks sessions, and maintains seat information [2][3]. When the service is restarted via the standard service manager, it generally triggers a stop operation that cleans up these sessions and seats, effectively terminating them [1][2]. Key technical considerations include: - Session Data Loss: Restarting the elogind service often results in the system failing to recognize previously active sessions, causing them to be considered stale or lost [4][5]. - Preferred Alternatives: To refresh configuration changes without terminating sessions, the command loginctl reload is recommended instead of restarting the service [1]. - Potential for Instability: Even if session processes (like the desktop environment or user shells) continue to run, the loss of elogind's tracking information can lead to various issues, such as failure to access system resources (e.g., audio, removable media) or improper handling of power management and shutdown requests [1][4][6][7]. In some specialized configurations, users may attempt to work around this by using specific signals to prevent the daemon from clearing session data upon exit, though this is generally discouraged and may not reliably preserve all session functionality across different distributions and software environments [4][6][2].
Citations:
🏁 Script executed:
Repository: unraid/webgui
Length of output: 4019
Avoid restarting elogind live This restarts elogind and can drop active login sessions; use a non-disruptive reload path or defer the change until reboot.
🤖 Prompt for AI Agents