systemd 服务单元启动失败

systemd 服务单元启动失败

我想在 Ubuntu 17.04 启动时更改某些 powertop 参数,因此我创建了一个 shell 脚本/usr/sbin/并使其可执行:

#!/bin/sh
echo 'min_power' > '/sys/class/scsi_host/host1/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host2/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host0/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host5/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host3/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host4/link_power_management_policy';
echo '1' > '/sys/module/snd_hda_intel/parameters/power_save';
echo 'auto' > '/sys/bus/i2c/devices/i2c-0/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-1/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-2/device/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1d.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.3/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.6/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:02.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:14.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.4/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:17.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.2/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:16.0/power/control';
ethtool -s  enp0s31f6 wol d
exit 0

然后我在以下位置创建了一个服务单元/etc/systemd/system

[Unit]
Description=PowerTOP

[Service]
ExecStart=/usr/sbin/powertop-stup.sh

[Install]
WantedBy=multi-user.target

并启用它sudo systemctl enable powertop_start.service 但重新启动后它不起作用。

如果我在启动后手动启动该服务,sudo systemctl start powertop_start.service它会完美运行。此外,当我启动 shell 脚本本身时,它会运行,但在启动时自动不执行任何操作。

答案1

我不知道为什么您的服务不起作用,但我相信在/sys启动时进行更改的标准方法是使用sysfsutils,所以我建议将其作为替代方法。

该包可能未默认安装,因此请先执行以下操作:

sudo apt install sysfsutils

现在编辑文件/etc/sysfs.conf,例如:

sudoedit /etc/sysfs.conf

并将这些行添加到其末尾

class/scsi_host/host1/link_power_management_policy = min_power
class/scsi_host/host2/link_power_management_policy = min_power
class/scsi_host/host0/link_power_management_policy = min_power
class/scsi_host/host5/link_power_management_policy = min_power
class/scsi_host/host3/link_power_management_policy = min_power 
class/scsi_host/host4/link_power_management_policy = min_power
module/snd_hda_intel/parameters/power_save = 1
bus/i2c/devices/i2c-0/device/power/control = auto
bus/i2c/devices/i2c-1/device/power/control = auto
bus/i2c/devices/i2c-2/device/power/control = auto
bus/pci/devices/0000:00:1d.0/power/control = auto
bus/pci/devices/0000:00:1f.3/power/control = auto
bus/pci/devices/0000:00:00.0/power/control = auto
bus/pci/devices/0000:00:1f.6/power/control = auto
bus/pci/devices/0000:00:02.0/power/control = auto
bus/pci/devices/0000:00:14.0/power/control = auto
bus/pci/devices/0000:00:1f.4/power/control = auto
bus/pci/devices/0000:00:17.0/power/control = auto
bus/pci/devices/0000:00:1f.2/power/control = auto
bus/pci/devices/0000:00:1c.0/power/control = auto
bus/pci/devices/0000:00:1f.0/power/control = auto
bus/pci/devices/0000:00:16.0/power/control = auto

保存文件并退出,然后重新启动。

剩下的就是你的ethtool命令,我没有解决方案,但你可以看看 systemd 是否只为你运行该命令,详细信息如下在 muru 的这个回答中

相关内容