使用 cron 启动系统服务 - SaltStack
start a system service using cron - SaltStack
我想用 /etc/tmpfiles.d/tmp.conf
和 运行 每天午夜的 cron 作业覆盖 /usr/lib/tmpfiles.d/
的默认值 tmp.conf。该服务需要 运行 为 systemd-tmpfiles --clean
。我怎样才能运行半夜服务,有人帮帮我吗?
示例代码:
tmp.conf:
file.managed:
- name: /etc/tmpfiles.d/tmp.conf
- source: salt://tmp/files/tmp.conf
- user: root
- mode: 644
- require:
- user: root
run_systemd-tmpfiles:
cron.present:
- user: root
- minute: 0
- hour: 0
- require:
- file: tmp.conf
enable_tmp_service:
service.running:
- name: systemd-tmpfiles --clean
- enable: True
- require:
- cron: run_systemd-tmpfiles
如果您只想将 运行 命令作为 cron 的一部分,则需要将 cron.present
设置为 运行 命令。
cron_systemd-tmpfiles:
cron.present:
- name: systemd-tmpfiles --clean
- user: root
- minute: 0
- hour: 0
- require:
- file: tmp.conf
如果你想 运行 它处于这种状态,你不能使用 tmpfile.service,你只需 运行 通过 cmd.run
命令,或者如果你只想要它 运行 当 file.managed 改变时,你可以使用 cmd.wait
run tmpfiles:
cmd.wait:
- name: systemd-tmpfiles --clean
- listen:
- file: tmp.conf
但是如果您使用的是 systemd,systemd-tmpfiles.service 已经 运行 启动,因此没有理由再次启用它。当它 运行s 在启动过程开始时,它将 运行 以相同的方式 tmpfile --clean 运行s.
我想用 /etc/tmpfiles.d/tmp.conf
和 运行 每天午夜的 cron 作业覆盖 /usr/lib/tmpfiles.d/
的默认值 tmp.conf。该服务需要 运行 为 systemd-tmpfiles --clean
。我怎样才能运行半夜服务,有人帮帮我吗?
示例代码:
tmp.conf:
file.managed:
- name: /etc/tmpfiles.d/tmp.conf
- source: salt://tmp/files/tmp.conf
- user: root
- mode: 644
- require:
- user: root
run_systemd-tmpfiles:
cron.present:
- user: root
- minute: 0
- hour: 0
- require:
- file: tmp.conf
enable_tmp_service:
service.running:
- name: systemd-tmpfiles --clean
- enable: True
- require:
- cron: run_systemd-tmpfiles
如果您只想将 运行 命令作为 cron 的一部分,则需要将 cron.present
设置为 运行 命令。
cron_systemd-tmpfiles:
cron.present:
- name: systemd-tmpfiles --clean
- user: root
- minute: 0
- hour: 0
- require:
- file: tmp.conf
如果你想 运行 它处于这种状态,你不能使用 tmpfile.service,你只需 运行 通过 cmd.run
命令,或者如果你只想要它 运行 当 file.managed 改变时,你可以使用 cmd.wait
run tmpfiles:
cmd.wait:
- name: systemd-tmpfiles --clean
- listen:
- file: tmp.conf
但是如果您使用的是 systemd,systemd-tmpfiles.service 已经 运行 启动,因此没有理由再次启用它。当它 运行s 在启动过程开始时,它将 运行 以相同的方式 tmpfile --clean 运行s.