Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

python - Django - Gunicorn - shutdown and reboot ubuntu

I've built an application in Django. While testing I've used manage.py runserver commando. Now when I am done, I've transferred the Django application to Gunicorn. All works fine, except one thing: The web application has an option to shutdown and reboot the Ubuntu server machine (for logged in admin users). When running the application using manage.py runserver, it had permissions to do it.

But now with gunicorn, it doesn't. However it's maybe not fully save, I now the risks and want to do it.

Does anyone have an option to shutdown and reboot the Ubuntu machine using the Django application?

With manage.py runserver I've used:

cmd = "sleep 5 && reboot"
result = subprocess.Popen(cmd, stdout=subprocess.PIPE,shell=True)

Thanks for the replies.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're wanting to grant additional permissions to the user account that's used to run your web server. I would be very hesitant to do that, but if you want to, I would only grant the specific reboot permission to it. Here's an answer that may help you do that: https://unix.stackexchange.com/a/465236


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...