Ubuntu: Run sudo script at startup under 15.04 using 'systemd'



Question:

I would like to run a script to turn the keyboard backlight off on my Asus at login (this answer did not work). Before the introduction of systemd in Ubuntu 15.04, I did this through /etc/rc.local using the command (sleep 10 && echo 0 > /sys/class/leds/asus::kbd_backlight/brightness). However, under systemd, this no longer works.

I tried to follow the instructions here to create a systemd service. But that didn't work. This is the text I used:

[Unit] Description=MBWD Keyboard Backlight OFF script

[Service] Type=oneshot ExecStart=/usr/lib/systemd/scripts/keyboard_backlight.sh #RemainAfterExit=yes [Install] WantedBy=multi-user.target

To call this script:

 #!/bin/bash   echo 0 | sudo tee /sys/class/leds/asus::kbd_backlight/brightness  

I then enabled the service, started the service, and used the systemctl preset command to enable the service at startup (I think that's what it does).

After all this, the systemctl status command indicates that the service is enabled, and when I systemctl start the service it does dim the keyboard. And, on reboot, that is at startup, it may work, because the keyboard does turn off when Ubuntu starts up.

HOWEVER, once I get to my login screen and login, the keyboard light comes back on. I've tried to finesse this issue by using both sleep 20 in the script and by creating a systemd.timer unit. Neither worked.

Can anyone help???


Solution:1

Surely not the best answer but you can switch from systemd to upstart by installing the package upstart-sysv.

sudo apt-get install upstart-sysv  


Solution:2

I finally solved this problem by using an rc-local.service and /etc/rc.local instead of creating a separate systemd service. Here is what I did:

  1. In terminal: systemctl enable rc-local.service
  2. In /etc/rc.local I put the following:

#!/bin/sh -e (sleep 20 && echo 0 > /sys/devices/platform/asus-nb-wmi/leds/asus::kbd_backlight/brightness) exit 0

  1. Make /etc/rc.local executable:

sudo chmod a+x /etc/rc.local

  1. To confirm, check the status of rc-local.service

systemctl status rc-local.service

It should show green and say active. That was it.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »