1

Is it true, that to make settings permanent in the Linux systems, the batch script way is the standard?

Today I found myself checking that the computer wake-up settings got reset after restart of the computer. I started to search over the Google that I need to setup a batch script for the changes to persist. Now, this kind of suggestion is kind of universal across these type of "rare configurations". It made me very nervous that nobody is talking about any configurations or the software responsible for Wake-up functionality, instead - some cheap looking batch scripts solutions are thrown in that are suppose to set the settings on the computer startup.

Is it true that I have to setup a batch script and there are no configurations for wakeup in the /etc/ or any other folder to set the permanent changes that are kept after shutdown or a restart?

I'm providing additional information:

naudotojas@naudotojas-N53SV:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 19.04
Release:    19.04
Codename:   disco
naudotojas@naudotojas-N53SV:~$ 

These settings I would like to be disabled after restarting Ubuntu, aka stay permanent:

naudotojas@naudotojas-N53SV:~$ cat /proc/acpi/wakeup | grep enabled
EHC1      S3    *enabled   pci:0000:00:1d.0
EHC2      S3    *enabled   pci:0000:00:1a.0
XHCI      S3    *enabled   pci:0000:04:00.0

This is the final result I would like to see after reboot:

EHC1      S3    *disabled   pci:0000:00:1d.0
EHC2      S3    *disabled   pci:0000:00:1a.0
XHCI      S3    *disabled   pci:0000:04:00.0

2 Answers2

2

The preferred way to do this is by creating a service with systemd.
Adding script in rc.local is the deprecated way.

  1. Create a script file wherever you wish. Ex: ~/scripts/disable-devices-as-wakeup.sh.
#!/bin/bash

declare -a devices=(EHC1 EHC2 XHCI) # <-- Add your entries here for device in "${devices[@]}"; do if grep -qw ^$device.*enabled /proc/acpi/wakeup; then sudo sh -c "echo $device > /proc/acpi/wakeup" fi done

  1. Test it by executing it from the terminal.

  2. If everything is okay then let's make a service.

$ touch ~/scripts/disable-devices-as-wakeup.service

~/scripts/disable-devices-as-wakeup.service -

[Unit]
Description=Disable devices as wakeup

[Service] ExecStart=/home/username/scripts/disable-devices-as-wakeup.sh Type=oneshot

[Install] WantedBy=multi-user.target

  1. Copy or move the service to /etc/systemd/system/.
$ sudo cp ~/scripts/disable-devices-as-wakeup.service /etc/systemd/system/
  1. Enable the service.
$ systemctl enable disable-devices-as-wakeup.service
  1. Restart the OS and check the status.
$ systemctl status disable-devices-as-wakeup.service

Detailed explanation found on https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/chap-managing_services_with_systemd

1

Thank you very much for your explanation Hrishikesh. I've used this in my system. Although there was a small mistake in the code. I'm not a coder, but someone else pointed this out. So for reference to others. The quotes should not be there in the first line. It should be:

#!/bin/bash
declare -a devices=( LID0 XHC1 )
for device in "${devices[@]}"; do
    if grep -qw ^$device.*disabled /proc/acpi/wakeup; then
        sudo sh -c "echo $device > /proc/acpi/wakeup"
    fi
done

Or "enabled" just what you want to achieve.

Bart
  • 11