From 7c593f2fc221dd2862e43954fee911ae6d2bea3a Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 4 Apr 2023 18:46:26 +0200 Subject: [PATCH 01/10] renamed venv to env --- .gitignore | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4822f1c..0266622 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ __pycache__ upload -venv +env diff --git a/README.md b/README.md index 134d08b..a4a48a7 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ cd git clone https://code.cronyakatsuki.xyz/crony/upfast . # Create the virtual environment and load it for user on default -python3 -m venv venv +python3 -m venv env # Activate the virtual environment -source venv/bin/activate +source env/bin/activate # Install all the requirements pip install -r requirements.txt @@ -52,7 +52,7 @@ Documentation=https://code.cronyakatsuki.xyz/crony/upfast User=upfast Group=upfast WorkingDirectory=/usr/local/upfast/ -ExecStart=/usr/local/upfast/venv/bin/uvicorn main:app --host 127.0.0.1 --port 8000 --proxy-headers --forwarded-allow-ips='*' +ExecStart=/usr/local/upfast/env/bin/uvicorn main:app --host 127.0.0.1 --port 8000 --proxy-headers --forwarded-allow-ips='*' Restart=on-failure ``` Finally run following commmands. From da70b22fdfbe88aace087dd3ddf39dd680b82f6a Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 4 Apr 2023 18:47:37 +0200 Subject: [PATCH 02/10] added upfast.sh for quick install and upfast.service --- upfast.service | 10 ++++++++++ upfast.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 upfast.service create mode 100755 upfast.sh diff --git a/upfast.service b/upfast.service new file mode 100644 index 0000000..c2843d1 --- /dev/null +++ b/upfast.service @@ -0,0 +1,10 @@ +[Unit] +Description=UpFast service +Documentation=https://code.cronyakatsuki.xyz/crony/upfast + +[Service] +User=upfast +Group=upfast +WorkingDirectory=/usr/local/upfast/ +ExecStart=/usr/local/upfast/env/bin/uvicorn main:app --host 127.0.0.1 --port 8000 --proxy-headers --forwarded-allow-ips='*' +Restart=on-failure diff --git a/upfast.sh b/upfast.sh new file mode 100755 index 0000000..f1838f0 --- /dev/null +++ b/upfast.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# quick install (and run) script for upfast using systemd +if [ $EUID -ne 0] +then + echo "Please run as root" + exit 1 +fi + +cp ./upfast.service /etc/systemd/system/upfast.service + +useradd --shell /bin/sh --system --home-dir /usr/local/upfast upfast +mkdir -p /usr/local/upfast # dodge copying of skeletons + +chown upfast:upfast /usr/local/upfast +chmod 700 /usr/local/upfast + +su upfast -c' +cd +git clone https://git.craftmenners.men/upfast . + +python3 -m venv env +. ./env/bin/activate +pip install -r requirements.txt +mkdir upload' + +systemctl enable --now upfast.service From b376d91e21805a000c6ad242a501f47908729e5b Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 4 Apr 2023 18:52:14 +0200 Subject: [PATCH 03/10] extracted nginx conf into file --- upfast-nginx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 upfast-nginx diff --git a/upfast-nginx b/upfast-nginx new file mode 100644 index 0000000..0494af8 --- /dev/null +++ b/upfast-nginx @@ -0,0 +1,15 @@ +server { + listen 80; + listen [::]:80; + + server_name upfast.example.com ; + + location / { + proxy_pass http://127.0.0.1:8000; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_redirect off; + proxy_buffering off; + } +} From 972f55f38dcdc717e92bd2a2b850410f87d8e6dd Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 5 Apr 2023 12:48:30 +0200 Subject: [PATCH 04/10] renamed upfast.sh to install.sh --- upfast.sh => install.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) rename upfast.sh => install.sh (93%) diff --git a/upfast.sh b/install.sh similarity index 93% rename from upfast.sh rename to install.sh index f1838f0..24b1801 100755 --- a/upfast.sh +++ b/install.sh @@ -7,8 +7,6 @@ then exit 1 fi -cp ./upfast.service /etc/systemd/system/upfast.service - useradd --shell /bin/sh --system --home-dir /usr/local/upfast upfast mkdir -p /usr/local/upfast # dodge copying of skeletons @@ -24,4 +22,4 @@ python3 -m venv env pip install -r requirements.txt mkdir upload' -systemctl enable --now upfast.service +cp ./upfast.service /etc/systemd/system/upfast.service From fb7b89a1014dcbdbcfd4b0549cb1c738f5162b5a Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 5 Apr 2023 12:54:38 +0200 Subject: [PATCH 05/10] added daemon reload to install script --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index 24b1801..783baee 100755 --- a/install.sh +++ b/install.sh @@ -23,3 +23,4 @@ pip install -r requirements.txt mkdir upload' cp ./upfast.service /etc/systemd/system/upfast.service +systemctl daemon reload From 1987a3fbef49369ecb5b4ee4976f923d54d69232 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 5 Apr 2023 12:54:52 +0200 Subject: [PATCH 06/10] added install section to service --- upfast.service | 3 +++ 1 file changed, 3 insertions(+) diff --git a/upfast.service b/upfast.service index c2843d1..4c860ec 100644 --- a/upfast.service +++ b/upfast.service @@ -8,3 +8,6 @@ Group=upfast WorkingDirectory=/usr/local/upfast/ ExecStart=/usr/local/upfast/env/bin/uvicorn main:app --host 127.0.0.1 --port 8000 --proxy-headers --forwarded-allow-ips='*' Restart=on-failure + +[Install] +WantedBy=multi-user.target From 76963bcd889ec70136f8deb3c81ab209f54274f9 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 5 Apr 2023 12:55:15 +0200 Subject: [PATCH 07/10] removed the files' content from readme --- README.md | 77 ++++++++----------------------------------------------- 1 file changed, 11 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index a4a48a7..6d18cb0 100644 --- a/README.md +++ b/README.md @@ -10,60 +10,20 @@ To run on a regular system I recommend to use a virtual environment to install t We will also be setting up an specific user to run the app as safe as possible with a systemd service file for startup +#### Installing ```bash -# Create the user (You can specify a different home-dir) -sudo useradd --shell /bin/bash --system \ - --home-dir "/usr/local/upfast" -m upfast - -# Change to upfast user and go to upfast dir -su upfast -cd - -# Clone the project directly into upfast-src directory -git clone https://code.cronyakatsuki.xyz/crony/upfast . - -# Create the virtual environment and load it for user on default -python3 -m venv env -# Activate the virtual environment -source env/bin/activate -# Install all the requirements -pip install -r requirements.txt - -# Load environment by default -echo "source /usr/local/upfast/venv/bin/activate" > "/usr/local/upfast/.profile" - -# create the upload directory -mkdir upload - -# UpFast go brrr -uvicorn main:app --host 127.0.0.1 --port 8000 --proxy-headers --forwarded-allow-ips='*' +./install.sh ``` -#### Autostart with systemd - -To autostart with systemd you will need to create a systemd .service file in path `/etc/systemd/system/upfast.service` and add this content to it. - -```systemd -[Unit] -Description=UpFast service -Documentation=https://code.cronyakatsuki.xyz/crony/upfast - -[Service] -User=upfast -Group=upfast -WorkingDirectory=/usr/local/upfast/ -ExecStart=/usr/local/upfast/env/bin/uvicorn main:app --host 127.0.0.1 --port 8000 --proxy-headers --forwarded-allow-ips='*' -Restart=on-failure -``` -Finally run following commmands. - +#### Running ```bash -# refresh services -sudo systemctl daemon-reload -# enable the service -sudo systemctl enable upfast.service +systemctl start upfast.service ``` +#### Start on boot +```bash +systemctl enable upfast.service +``` ### Docker In the repo there is an included dockerfile to generate an image from the latest version of everything, to generate an image just run `docker build . -t upfast` (You need root privileges or to be in the docker group). @@ -80,22 +40,7 @@ The sample command will need an upload directory, you can replace `./upload` wit ### Nginx Proxy setup This is an example nginx proxy config for http - -```nginx -server { - - listen 80; - listen [::]:80; - - server_name upfast.example.com ; - - location / { - proxy_pass http://127.0.0.1:8000; - proxy_set_header Host $host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_redirect off; - proxy_buffering off; - } -} +```bash +cp ./upfast-nginx /etc/nginx/sites-available/upfast +ln -sf /etc/nginx/sites-available/upfast /etc/nginx/sites-enabled/ ``` From 17c172a73d878f73f882048f63e2ab587ec76f6b Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 5 Apr 2023 12:58:28 +0200 Subject: [PATCH 08/10] added loading for the nginx config --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 6d18cb0..bad5ed6 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,8 @@ This is an example nginx proxy config for http cp ./upfast-nginx /etc/nginx/sites-available/upfast ln -sf /etc/nginx/sites-available/upfast /etc/nginx/sites-enabled/ ``` + +> Load config +```bash +systemctl reload nginx +``` From 3d1ba3bb5c630bfece1fb0453dd45cc554af9858 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 5 Apr 2023 13:04:05 +0200 Subject: [PATCH 09/10] use cronyakatsuk instead of craftmenners s: --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 783baee..f0adcc1 100755 --- a/install.sh +++ b/install.sh @@ -15,7 +15,7 @@ chmod 700 /usr/local/upfast su upfast -c' cd -git clone https://git.craftmenners.men/upfast . +git clone https://code.cronyakatsuki.xyz/crony/upfast . python3 -m venv env . ./env/bin/activate From e9563be67a23051be08e48cf91bbb009bf994835 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 5 Apr 2023 13:05:34 +0200 Subject: [PATCH 10/10] fixed typo --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index f0adcc1..8dd5660 100755 --- a/install.sh +++ b/install.sh @@ -23,4 +23,4 @@ pip install -r requirements.txt mkdir upload' cp ./upfast.service /etc/systemd/system/upfast.service -systemctl daemon reload +systemctl daemon-reload