Systemd 服务启动太早并且无法自动重启

Systemd 服务启动太早并且无法自动重启

每次启动时,我都需要通过 pactl 手动修复麦克风源和音量。否则,它们会随机改变。

为此,我制作了一个脚本 - mic.sh,当我单独运行它时,它的工作原理与预期完全一样。

我正在尝试将其变成每次启动时都会启动的 systemd 服务,而不必手动执行此操作。

问题是,(我的想法),服务启动得太早并且无法连接到pulseaudio。

因此,我更改了服务,在失败时重新启动 5 次,间隔 30 秒。

即使自动重启也不起作用。这让我觉得这不是太早开始的问题吗?因为,在我等待服务完成最后一次重新启动(第五次)时,我能够手动运行脚本,并且它有效。

[Unit]
Description=mic.sh
StartLimitIntervalSec=240
StartLimitBurst=5

[Service]
Restart=on-failure
RestartSec=30
ExecStart=/home/rain/sh/mic.sh

[Install]
WantedBy=multi-user.target


##############################


rain@pop-os:~$ sudo systemctl status micsh.service
● micsh.service - mic.sh
     Loaded: loaded (/etc/systemd/system/micsh.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Sat 2020-07-25 23:40:11 IST; 17s ago
    Process: 1993 ExecStart=/home/rain/sh/mic.sh (code=exited, status=1/FAILURE)
   Main PID: 1993 (code=exited, status=1/FAILURE)

Jul 25 23:40:11 pop-os systemd[1]: micsh.service: Main process exited, code=exited, status=1/FAILURE
Jul 25 23:40:11 pop-os systemd[1]: micsh.service: Failed with result 'exit-code'.



rain@pop-os:~$ sudo systemctl status micsh.service
● micsh.service - mic.sh
     Loaded: loaded (/etc/systemd/system/micsh.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Sat 2020-07-25 23:40:41 IST; 8s ago
    Process: 2130 ExecStart=/home/rain/sh/mic.sh (code=exited, status=1/FAILURE)
   Main PID: 2130 (code=exited, status=1/FAILURE)



rain@pop-os:~$ sudo systemctl status micsh.service
● micsh.service - mic.sh
     Loaded: loaded (/etc/systemd/system/micsh.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2020-07-25 23:42:11 IST; 1min 11s ago
    Process: 2238 ExecStart=/home/rain/sh/mic.sh (code=exited, status=1/FAILURE)
   Main PID: 2238 (code=exited, status=1/FAILURE)

Jul 25 23:42:11 pop-os systemd[1]: micsh.service: Scheduled restart job, restart counter is at 5.
Jul 25 23:42:11 pop-os systemd[1]: Stopped mic.sh.
Jul 25 23:42:11 pop-os systemd[1]: micsh.service: Start request repeated too quickly.
Jul 25 23:42:11 pop-os systemd[1]: micsh.service: Failed with result 'exit-code'.
Jul 25 23:42:11 pop-os systemd[1]: Failed to start mic.sh.```

答案1

SystemD 在系统启动时发生,在您登录之前。

您应该将.desktop文件放入$HOME/.config/autostart.

相关内容