Systemd
systemd is a suite of basic building blocks for a Linux system. It provides a system and service manager that runs as PID 1 and starts the rest of the system.
archlinux Wiki
i3wm 普通用户关机 重新安装 polkit 即可
root
systemctl=systemctl --systemsystemctl enable NetworkManager=systemctl --system enable NetworkManagersystemctl enable sshd=systemctl enable sshd --systemsystemctl enable update-system.timer=systemctl --system enable update-system.timer
poweroff
systemctl poweroff
reboot
systemctl reboot
Show system status
systemctl status
List running units
systemctl
systemctl list-units
List failed units
systemctl --failed
List installed unit files
systemctl list-unit-files
not root
参考archlinux wiki
offers the ability to manage services under the user’s control with a per-user systemd instance,enabling them to start, stop, enable, and disable their own user units systemctl --user Connect to user service manager
systemctl --user enable mpdsystemctl --user start mpd
systemd/Timers
There are many cron implementations, but none of them are installed by default as the base system uses systemd/Timers instead.
archlinux Wiki
systemd.timer
systemd.time 执行时间策略
systemd.exec
file path
- /etc/systemd/system/update-system.timer
- /etc/systemd/system/update-system.service
update-system.timer
[Unit]
Description=update system weekly
[Timer]
OnCalendar= Fri *-*-* 12:00:00
[Install]
WantedBy=timers.target
update-system.service
[Unit]
Description=update system weekly
[Service]
ExecStart=pacman -S -y --noconfirm -u
查看定时任务
systemctl list-timers
systemctl list-timers --all
开机激活定时器
systemctl enable update-system.timer
取消开机激活定时器
systemctl disable update-system.timer
手动激活定时器
systemctl start update-system.timer
手动停止定时器
systemctl stop update-system.timer
查看定时器状态
systemctl status update-system.timer
OnCalendar
systemd-analyze calendar weekly
systemd-analyze calendar "Mon *-*-* 00:00:00"
注意 / 仅用于月份
| desc | word | 周 年-月-日 时:分:秒 |
|---|---|---|
| 每分钟 | minutely | *-*-* *:*:00 |
| 从0分钟起每5分钟 | minutely | *-*-* *:00/5:00 |
| 每小时 | hourly | *-*-* *:00:00 |
| 每天 | daily | *-*-* 00:00:00 |
| 每月 | monthly | *-*-01 00:00:00 |
| 每周 | weekly | Mon *-*-* 00:00:00 |
| 每年 | yearly /annually | *-01-01 00:00:00 |
| 每季度 | quarterly | *-01,04,07,10-01 00:00:00 |
| 每半年 | semiannually | *-01,07-01 00:00:00 |
| 九月倒数第一天0点 | *-09~01 00:00:00 | |
| 每年的九月倒数第七天起每过4天后的周一 | Mon *-09~07/4 00:00:00 | |
| 下一个周一或周五 | Mon,Fri *-*-* 00:00:00 | |
| 周一到周五每天0点 | Mon..Fri *-*-* 00:00:00 |