How do I make a systemd service and enable it?

I’m trying to make this one:

/etc/systemd/system/startup-brightness.service

[Unit]
Description=Set lower brightness on startup
After=systemd-backlight@backlight:amdgpu_bl0.service

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo 25 > /sys/class/backlight/amdgpu_bl0/brightness'

[Install]
WantedBy=systemd-backlight@backlight:amdgpu_bl0.service

But I don’t know how. Any assistance is greatly appreciated. Thank you.

2 Likes

Create and open the service file with Nano (or your favorite text editor) and paste the contents into it:

sudo nano /etc/systemd/system/startup-brightness.service

Enable and start the service:

systemctl enable --now startup-brightness.service
3 Likes

Hi @Yochanan,

This is the output:

[kev@Stormy ~]$ systemctl --user enable --now startup-brightness.service
Created symlink /home/kev/.config/systemd/user/systemd-backlight@backlight:amdgpu_bl0.service.wants/startup-brightness.service → /etc/xdg/systemd/user/startup-brightness.service.
Job for startup-brightness.service failed because the control process exited with error code.
See "systemctl --user status startup-brightness.service" and "journalctl --user -xe" for details.
[kev@Stormy ~]$ systemctl --user status startup-brightness.service
● startup-brightness.service - Set lower brightness on startup
     Loaded: loaded (/etc/xdg/systemd/user/startup-brightness.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2020-09-06 10:35:13 WIB; 18s ago
    Process: 8674 ExecStart=/bin/bash -c echo 25 > /sys/class/backlight/amdgpu_bl0/brightness (code=exited, status=1/FAILURE)
   Main PID: 8674 (code=exited, status=1/FAILURE)

Sep 06 10:35:13 Stormy systemd[1157]: Starting Set lower brightness on startup...
Sep 06 10:35:13 Stormy bash[8674]: /bin/bash: /sys/class/backlight/amdgpu_bl0/brightness: Permission denied
Sep 06 10:35:13 Stormy systemd[1157]: startup-brightness.service: Main process exited, code=exited, status=1/FAILURE
Sep 06 10:35:13 Stormy systemd[1157]: startup-brightness.service: Failed with result 'exit-code'.
Sep 06 10:35:13 Stormy systemd[1157]: Failed to start Set lower brightness on startup.

Use /usr/bin/bash

Won’t make a difference as /bin already is a symlink to /usr/bin:

$ ls -l /bin
lrwxrwxrwx 1 root root 7 21. Mai 09:30 /bin -> usr/bin

This is a permission problem - the user is not allowed to write to that file.

@gamalkevin: Don’t create a user service - create a system service instead.

3 Likes

Don’t forget to reload the systemctl daemon, the files is not being read, they are in memory.

For --user

systemctl --user daemon-reload

Doh! I knew that… I’ll edit my above post that’s marked as the solution.

Thank you for the help Yochanan, @freggel.doe, @freed00m.

Now it works. :smiley:

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.