From c5e55fbcb974f91c1a790b1772b5d4cb92786ed3 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Thu, 31 Aug 2023 14:21:38 +0400 Subject: [PATCH 1/5] Systemd unit, init script --- txtdot.init | 27 +++++++++++++++++++++++++++ txtdot.service | 13 +++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 txtdot.init create mode 100644 txtdot.service diff --git a/txtdot.init b/txtdot.init new file mode 100644 index 0000000..ce68d95 --- /dev/null +++ b/txtdot.init @@ -0,0 +1,27 @@ +#!/sbin/openrc-run + +#export HOST=127.0.0.1 +#export PORT=8080 +#export REVERSE_PROXY=true + +name=$RC_SVCNAME +command="/usr/bin/node" +command_args="./src/app.js" +command_user="txtdot" +directory="/home/txtdot/src/dist" + +output_log="/var/log/$RC_SVCNAME/txtdot.log" +error_log="/var/log/$RC_SVCNAME/error.log" + +pidfile="/run/$RC_SVCNAME/$RC_SVCNAME.pid" +stopsig="KILL" +command_background="yes" + +depend() { + need net +} + +start_pre() { + checkpath --directory --owner $command_user:$command_user --mode 0775 \ + /run/$RC_SVCNAME /var/log/$RC_SVCNAME +} diff --git a/txtdot.service b/txtdot.service new file mode 100644 index 0000000..905a85b --- /dev/null +++ b/txtdot.service @@ -0,0 +1,13 @@ +[Unit] +Description=txtdot proxy server +After=network.target + +[Service] +User=txtdot +Group=txtdot +WorkingDirectory=/home/txtdot/src/dist +ExecStart=/usr/bin/node ./src/app.js +Restart=always + +[Install] +WantedBy=default.target From c6bac932ce9ff8b7522525acd6395ce6311f9c70 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Thu, 31 Aug 2023 14:26:53 +0400 Subject: [PATCH 2/5] Nginx config --- nginx.conf | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 nginx.conf diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..b70acc5 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,22 @@ +limit_req_zone $binary_remote_addr zone=txtdotapi:10m rate=2r/s; + +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + + server_name txt.dc09.ru; + + location / { + limit_req zone=txtdotapi burst=4; + proxy_pass http://127.0.0.1:8080; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /static/ { + alias /home/txtdot/src/dist/static/; + } +} From b1d532660765e604a8e4e959611810d7c5366174 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Thu, 31 Aug 2023 14:33:35 +0400 Subject: [PATCH 3/5] Env in init script is not a good idea --- txtdot.init | 4 ---- 1 file changed, 4 deletions(-) diff --git a/txtdot.init b/txtdot.init index ce68d95..aaf9ce9 100644 --- a/txtdot.init +++ b/txtdot.init @@ -1,9 +1,5 @@ #!/sbin/openrc-run -#export HOST=127.0.0.1 -#export PORT=8080 -#export REVERSE_PROXY=true - name=$RC_SVCNAME command="/usr/bin/node" command_args="./src/app.js" From f98f6d69ac51ba3ff411ba0785c3a986fffacb4c Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Thu, 31 Aug 2023 17:25:14 +0400 Subject: [PATCH 4/5] Refactor: move init config to init/ --- txtdot.init => init/txtdot.init | 0 txtdot.service => init/txtdot.service | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename txtdot.init => init/txtdot.init (100%) rename txtdot.service => init/txtdot.service (100%) diff --git a/txtdot.init b/init/txtdot.init similarity index 100% rename from txtdot.init rename to init/txtdot.init diff --git a/txtdot.service b/init/txtdot.service similarity index 100% rename from txtdot.service rename to init/txtdot.service From 148e00bd0cc8de04e0c4f2bb67b61533e69c9983 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Thu, 31 Aug 2023 17:37:50 +0400 Subject: [PATCH 5/5] Refactor: config folder for init and nginx.conf --- nginx.conf => config/nginx.conf | 0 {init => config}/txtdot.init | 0 {init => config}/txtdot.service | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename nginx.conf => config/nginx.conf (100%) rename {init => config}/txtdot.init (100%) rename {init => config}/txtdot.service (100%) diff --git a/nginx.conf b/config/nginx.conf similarity index 100% rename from nginx.conf rename to config/nginx.conf diff --git a/init/txtdot.init b/config/txtdot.init similarity index 100% rename from init/txtdot.init rename to config/txtdot.init diff --git a/init/txtdot.service b/config/txtdot.service similarity index 100% rename from init/txtdot.service rename to config/txtdot.service