繁体   English   中英

如何从 python 脚本重新启动 nginx?

[英]How do I restart nginx from a python script?

我可以使用"nginx -s reload"命令在 shell 上重新启动 nginx。 但是,当我使用os.system("nginx -s reload")命令时,会出现错误。

/usr/local/bin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory对于此错误。 我已经安装了pcre。 是不是有一些魔法问题。

要在 python 脚本中运行此类命令,最好使用 subprocess library

试试这个代码而不是你的:

import subprocess
subprocess.call('whatever command you want to run it in terminal', shell=True)

走运

您好,我建议您在发送重置之前先发送此验证,以免头疼

reinicioNGINX = subprocess.getoutput(['nginx -t'])

如果'nginx:配置文件/etc/nginx/nginx.conf语法没问题'在reinicioNGINX中:

_command_restart

别的:

_command_avoid_restart

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM