Created
July 22, 2018 19:13
-
-
Save eyJhb/9668061f06163421b5b46b61f41d2c48 to your computer and use it in GitHub Desktop.
Simple flask web server to shutdown and restart a server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
import subprocess | |
app = Flask(__name__) | |
@app.route("/") | |
def index(): | |
return "Please visit /shutdown or /restart" | |
@app.route("/restart") | |
def restart(): | |
subprocess.run("shutdown -r 0", shell=True, check=True) | |
return "Restarting" | |
@app.route("/shutdown") | |
def shutdown(): | |
subprocess.run("shutdown -h 0", shell=True, check=True) | |
return "Shutting down!" | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0', port=5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment