Mongodb 不会通过子进程调用重新启动



我正在尝试从浏览器重新启动mongodb。以下是我使用django框架编写的代码:

def restart_db_mongo(request):
if request.method == 'POST':
restart_cmd = ["sudo","systemctl","restart","mongodb"]
p = subprocess.Popen(restart_cmd,stdout=subprocess.PIPE)
(output, err) = p.communicate()
if err is not None:
return JsonResponse({"err_code":1,"err_description":str(err)},safe=False)
status_cmd = ["sudo","systemctl","status","mongodb"]
p = subprocess.Popen(status_cmd,stdout=subprocess.PIPE)
(output, err) = p.communicate()
if 'active (running)' in output:
return JsonResponse({"err_code":0,"err_description":"Restarted successfully!"},safe=False)
else:
return JsonResponse({"err_code":1,"err_description":str(err)},safe=False)
else:
return JsonResponse({"err_code":2,"err_description":"Bad request"}, safe=False)

我的问题是mongodb无法重新启动。事实上,它在没有错误的情况下完成了第一个子流程调用,但状态仍然处于非活动状态。在交互式环境中,我已经验证了这些命令是否有效。我正在使用apache2来运行我的web应用程序。

通过检查apache2的日志,我发现我需要使用www-data ALL=(ALL) NOPASSWD:ALLwww-data添加到无密码列表中。现在它就像一个符咒。

最新更新