| 用途 | 服务账号自助定时任务 |
|---|---|
| 路径 | ~/.config/systemd/user/*.timer |
| 常驻 | loginctl enable-linger 用户名 |
创建与启用
创建与启用
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/hello.timer <<'EOF'
[Unit]
Description=user hello
[Timer]
OnCalendar=*-*-* *:00:00
[Install]
WantedBy=timers.target
EOF
cat > ~/.config/systemd/user/hello.service <<'EOF'
[Unit]
Description=user hello job
[Service]
Type=oneshot
ExecStart=/home/deploy/bin/hello.sh
EOF
systemctl --user daemon-reload
systemctl --user enable --now hello.timer
systemctl --user list-timers --no-pager退出登录仍运行
退出登录仍运行
sudo loginctl enable-linger deploy
loginctl show-user deploy | grep Linger用户级 unit 的日志:journalctl --user -u hello.service;跨用户排查要分别切到对应用户会话。