Skip to content

Instantly share code, notes, and snippets.

@eyJhb
Created July 22, 2018 19:13
Show Gist options
  • Save eyJhb/9668061f06163421b5b46b61f41d2c48 to your computer and use it in GitHub Desktop.
Save eyJhb/9668061f06163421b5b46b61f41d2c48 to your computer and use it in GitHub Desktop.
Simple flask web server to shutdown and restart a server
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