使用systemd在另一个服务运行时停止一个服务

我正在设置一个systemd服务来从letsencrypt更新我的SSL证书。 我想工作的是一个systemd计时器来停止nginx服务,运行我的证书更新脚本,然后重新启动nginx。

systemd有一些聪明的方法来做到这一点? 或者我只需要在脚本本身中执行相关的停止和启动操作?

systemd有一些聪明的方法来做到这一点? 或者我只需要在脚本本身中执行相关的停止和启动操作?

不,没有“聪明的方式”。 简单的说

systemctl stop <whatever> 

 systemctl start <whatever> 

在你的更新脚本中必要时,

Letsencrypt有一个预先和后续更新挂钩。

添加这个

 [renewal-params] # Other settings pre-hook=systemctl stop <service name> post-hook=systemctl start <service name> 

/etc/letsencrypt/renewal/<domain name>.conf将会停止并且每次运行certbot renew启动服务。

如果我理解正确,你想安排nginx stop来减less停机时间。

我不知道系统D,但任何UNIX命令,你可以使用“在”来build立自己的命令。

例如

 echo "systemctll stop nginx && mv /etc/my/cert/new.cert && systemctll start nginx" | at -m 5:00