diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ec62766 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +test: + python3 app.py +pip: + sudo pip3 install -r requirements.txt +deploy: pip + cp sample.service new.service + # yes, this exists because I'm too lazy to escape regex + inline 'sed' + python3 sed.py + sudo mv new.service /etc/systemd/system/simplefeedback.service + sudo systemctl daemon-reload + sudo systemctl enable --now simplefeedback.service +undeploy: + sudo systemctl stop simplefeedback.service + sudo systemctl disable simplefeedback.service + sudo rm /etc/systemd/system/simplefeedback.service + sudo systemctl daemon-reload +update: + make undeploy + git pull + make deploy diff --git a/sample.service b/sample.service new file mode 100644 index 0000000..51234d2 --- /dev/null +++ b/sample.service @@ -0,0 +1,13 @@ +[Unit] +Description=SimpleFeedback gunicorn service + +[Service] +# WHO is edited by sed.py to become the current user +User=WHO +Type=simple +# GCPATH is edited by sed.py to point to the user's installation of gunicorn +# PATH becomes the output of `pwd` +ExecStart=GCPATH --chdir PATH --workers=8 --bind=0.0.0.0:6969 app:app + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/sed.py b/sed.py new file mode 100644 index 0000000..c4fc765 --- /dev/null +++ b/sed.py @@ -0,0 +1,18 @@ +import os, subprocess, getpass + +# Feel free to edit this file, but note that `make deploy` expects the service file to be output as `new.service` +# It, of course, is renamed to `localizer.service` as it's moved to `/etc/systemd/system/` + +text = open("new.service").read() +text = text.replace( + "GCPATH", + subprocess.check_output(["/usr/bin/bash", "-c", "which gunicorn"]) + .decode("utf-8") + .strip(), +) +text = text.replace("PATH", os.getcwd()) +text = text.replace("WHO", getpass.getuser()) + +os.remove("new.service") +with open("new.service", "w") as f: + f.write(text) diff --git a/settings.yaml b/settings.yaml index 43e9552..9c3837e 100644 --- a/settings.yaml +++ b/settings.yaml @@ -1,5 +1,5 @@ app_dist: "Crystal Linux" camp_extra: "Please note that this particular event is only able to ship to the US and Canada." host: "0.0.0.0" -port: 9090 +port: 6969 debug: true \ No newline at end of file