我有 Debian Jessie 并通过 ssh 连接到它。我想在 systemd 用户登录时自动启动 shell 命令。
我创建了一个简单的 systemd 服务~/.config/systemd/user/foo.service女巫,其中包含:
[Unit]
Description=Systemd autostart test
Wants=local-fs.target
After=local-fs.target
[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo 123 >> /home/user/there;"
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
我已经通过 systemctl 启用它
systemctl --user enable foo
Run Code Online (Sandbox Code Playgroud)
我已经创建了成功消息容器
touch ~/there
Run Code Online (Sandbox Code Playgroud)
并在重新启动和登录(通过 ssh)后~/there文件为空。
当我手动使用它时
systemctl --user restart foo
Run Code Online (Sandbox Code Playgroud)
有用。
我错过了什么?