Systemd

archlinux Wiki
i3wm 普通用户关机 重新安装 polkit 即可

root

  • systemctl = systemctl –system
  • systemctl enable NetworkManager = systemctl –system enable NetworkManager
  • systemctl enable sshd = systemctl enable sshd –system
  • systemctl enable update-system.timer = systemctl –system enable update-system.timer

poweroff

1
systemctl poweroff

reboot

1
systemctl reboot

Show system status

1
systemctl status

List running units

1
2
systemctl
systemctl list-units

List failed units

1
systemctl --failed

List installed unit files

1
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 mpd
  • systemctl –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

1
2
3
4
5
6
7
8
[Unit]
Description=update system weekly

[Timer]
OnCalendar= Fri *-*-* 12:00:00

[Install]
WantedBy=timers.target

update-system.service

1
2
3
4
5
[Unit]
Description=update system weekly

[Service]
ExecStart=pacman -S -y --noconfirm -u

查看定时任务

1
2
systemctl list-timers
systemctl list-timers --all

开机激活定时器

1
systemctl enable update-system.timer

取消开机激活定时器

1
systemctl disable update-system.timer

手动激活定时器

1
systemctl start update-system.timer

手动停止定时器

1
systemctl stop update-system.timer

查看定时器状态

1
systemctl status update-system.timer

OnCalendar

1
2
systemd-analyze calendar weekly
systemd-analyze calendar "Mon *-*-* 00:00:00"

注意 / 仅用于月份

descword周 年-月-日 时:分:秒
每分钟minutely*-*-* *:*:00
从0分钟起每5分钟minutely*-*-* *:00/5:00
每小时hourly*-*-* *:00:00
每天daily*-*-* 00:00:00
每月monthly*-*-01 00:00:00
每周weeklyMon *-*-* 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