重新启动nginx和gunicorn没有sudo

我可以运行systemctl restart gunicorn && systemctl restart nginx没有sudo ? 目前我得到:

出:authentication是需要重新加载'gunicorn.service'。

out:身份validation:myuser

输出:密码:

 # coding: utf-8 from fabric.api import * from fabric.colors import green, red def production(): env.host_string = '159.xxx.xxx.xx' env.user = 'myuser' path = "/home/myuser/myproject/myproject" print(red("Beginning Deploy:")) with cd(path): with prefix('. /home/myuser/myproject/myenv/bin/activate'): run("pwd") print(green("Pulling master from git...")) run("git pull") print(green("Migrate the database...")) run("python3 manage.py migrate") print(green("Restart the uwsgi process")) run("systemctl restart gunicorn && systemctl restart nginx") print(red("DONE!")) 

您可以尝试添加PolicyKit规则,以允许在没有身份validation的情况下重新启动设备。

例如,这将允许任何用户重新启动指定的服务(可能需要一点调整):

 polkit.addRule(function(action, subject) { if (action.id == "org.freedesktop.systemd1.manage-units") { polkit.log("action=" + action) polkit.log("subject=" + subject) polkit.log("unit="+action.lookup("unit")) polkit.log("verb="+action.lookup("verb")) if (action.lookup("unit") == "gunicorn.service" || action.lookup("unit") == "nginx.service") { var verb = action.lookup("verb"); if (verb == "start" || verb == "restart") { polkit.log("returning YES") return polkit.Result.YES; } } } polkit.log("returning NO") }); 

将您的规则放置在/etc/polkit-1/rules.d目录中的文件中,文件名以.rules结尾。

这需要systemd 226或更高版本,在Ubuntu中是指16.04 LTS或更高版本。

(如果你认为这看起来像JavaScript,那是因为它是JavaScript 。)

您也可以通过检查subject.user来限制它到特定的用户,例如:

 if (subject.user == "deploy" || subject.user == "me") {