So I wrote a systemd service file for Manjaro Linux to run two shell commands to set some kernel parameters at runtime to enable custom power saving actions.

BTW: This was a tip by a german computer magazine. Originally I should place the shell commands in the /etc/rc.local file but I want to make it with a systemd service. Because rc.local is considered as deprecated and I want to learn something new.

Below you see my service file saved as /etc/systemd/system/power-savings.service. Because there are two ExecStart directives I have chosen Type=oneshot.

Description=Enable custom power saving actions provided by c't magazine
# Quelle(n):  c't 25/2016, S. 77
#             c't 26/2016, S. 12

# SATA Link Power Management aktivieren
ExecStart=/usr/bin/sh -c 'for I in /sys/class/scsi_host/host?/link_power_management_policy; do echo min_power > $I; done'
# Energieverwaltung für den Audiocodec aktivieren
ExecStart=/usr/bin/sh -c 'echo 1 > /sys/module/snd_hda_intel/parameters/power_save'


I verified the service file with:

$ sudo systemd-analyze verify /etc/systemd/system/power-savings.service

Then I reloaded the daemon with:

$ sudo systemctl daemon-reload

I enabled it with:

$ sudo systemctl enable power-savings.service

Then I have run the service with:

$ sudo systemctl start power-savings.service

And it worked! The kernel parameters have been set.

But then, after rebooting my system the service seems not to have any effect. Although, the service status said success...

$ systemctl status power-savings.service

Process: 412 ExecStart=/usr/bin/bash -c echo 1 > /sys/module/snd_hda_intel/parameters/power_save (code=exited, status=0/SUCCESS)
Process: 404 ExecStart=/usr/bin/bash -c for I in /sys/class/scsi_host/host?/link_power_management_policy; do echo min_power > $I; done (code=exited, status=0/SUCCESS)
Main PID: 412 (code=exited, status=0/SUCCESS)

But the kernel parameter were not set. So my service works during a user session, only. Unfortunately not during system boot up as it was intended to work.

Is there something I might have missed? Do I need some of those After or Require directives? How am I able to debug what really happens with the ExecStart directives?


Doing further research on my problem I found an interesting statement from the Arch Linux community. In this post user calzon65 is trying to do something similar as I do.

The discussion redirected me to an article about tmpfiles.d which could be a possible solution for writing values into files instead of using pipes or redirects. However this article has an interesting note:

This method may not work to set options in /sys since the systemd-tmpfiles-setup service may run before the appropriate device modules is loaded.

What our projects have in common is that we both indeed try to write to /sys/... during system boot up. This fact is probably the answer to the question why it is not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.