s.p*_*zko 3 linux embedded systemd
我想要一个在第一次运行和重新启动服务时表现不同的服务。这可以用 systemd 实现吗?(我在嵌入式操作系统中使用 systemd)。
我尝试使用 ExecReload 和 ExecStart,但仅当我使用命令“systemctl restart”时才运行 ExecReload。另一方面 ExecStart 在服务重启后运行(我有 Restart=on-failure 和 RestartSec=5)。
您可以使用systemctl set-environment将一些值推送到服务的未来运行中。例如,对于一个单位:
[Unit]
Description=testing
[Service]
Type=oneshot
ExecStart=/my/command myarg1 ${MYDONE}
ExecStart=/usr/bin/systemctl set-environment MYDONE=1
[Install]
Run Code Online (Sandbox Code Playgroud)
在第一个systemctl start <unit>最后ARG传递给/my/command会''和MYDONE不会的环境。在起步较晚,最后ARG会1和MYDONE=1将在环境中。