From 5dd20cd6a0031589e5b34fb4e5eeaadb19c04080 Mon Sep 17 00:00:00 2001 From: Max Nuding Date: Tue, 4 Apr 2023 12:32:04 +0200 Subject: [PATCH] Fix #17 and improve instructions --- README.md | 46 +++++++++++++++++++++++----------- moshing-mammut.service.EXAMPLE | 9 +++---- start.sh.EXAMPLE | 2 +- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index de59b56..fca1329 100644 --- a/README.md +++ b/README.md @@ -46,32 +46,50 @@ This might not be the ideal setup to run this, but here's how I am doing it. Ins or Debian derivative, using Apache as HTTP Proxy. Other setups are possible, but not covered here. By default, NVM is used to install NodeJS, but you can install it any way you want. -This is based on [SvelteKit's instructions](https://kit.svelte.dev/docs/adapter-node#deploying) +This is based on [SvelteKit's instructions](https://kit.svelte.dev/docs/adapter-node#deploying) and [How To Deploy Node.js Applications Using Systemd and Nginx](https://www.digitalocean.com/community/tutorials/how-to-deploy-node-js-applications-using-systemd-and-nginx) -On your server, install the requirements: -- Apache2 HTTP Server -- NodeJS (via [NVM](https://github.com/nvm-sh/nvm)) #### On your server -Create a directory for the app. This will be called `$APP_DIR` from now on. +Install Apache2 if not already installed. -Place `package.json`, `apache2.conf.EXAMPLE`, `moshing-mammut.service.EXAMPLE` and `start.sh.EXAMPLE` in this directory. +Copy `apache2.conf.EXAMPLE` and `moshing-mammut.service.EXAMPLE` to your server. + +Set up a user for the app: `useradd -mrU moshing-mammut` + +Switch to your newly created user: `su moshing-mammut` + +Set up NVM: + +``` +$ cd +$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh +$ source ~/.nvm/nvm.sh +$ nvm install --lts +``` + +Create a directory for the app. This will be called `$APP_DIR` from now on. I use `/home/moshing-mammut/app`. + +Enter `$APP_DIR`. + +Place `package-lock.json` and `start.sh.EXAMPLE` in this directory. +Run `npm ci --omit dev` to install the dependencies. + + +Rename `start.sh.EXAMPLE` to `start.sh` and set the path to your NVM. + +If you do not have NVM installed, simply remove the line and make sure your node executable can be found either by +specifying the full path or by adding it to your $PATH. + +Exit out of your `moshing-mammut` user shell. Copy `apache2.conf.EXAMPLE` to `/etc/apache2/sites-available/moshingmammut.conf` and replace `ServerName` with your Domain. If you do not need or want SSL support, remove the whole `` block. If you do, add the path to your SSLCertificateFile and SSLCertificateKeyFile. Copy `moshing-mammut.service.EXAMPLE` to `/etc/systemd/system/moshing-mammut.service` -and replace `/PATH_TO_MOSHING_MAMMUT` with your `$APP_DIR`. Also replace `MOSHING_MAMMUT_USER` with the user you want -to run the app as. +and set your `User`, `Group`, `ExecStart` and `WorkingDirectory` accordingly. -Rename `start.sh.EXAMPLE` to `start.sh` and replace `/PATH_TO_YOUR_NVM/.nvm/nvm.sh` with the path to your NVM -installation. -If you do not have NVM installed, simply remove the line and make sure your node executable can be found either by -specifying the full path or by adding it to your $PATH. - -Run `npm ci --omit dev` to install the dependencies. #### On your development machine diff --git a/moshing-mammut.service.EXAMPLE b/moshing-mammut.service.EXAMPLE index 1073980..cc0cbba 100644 --- a/moshing-mammut.service.EXAMPLE +++ b/moshing-mammut.service.EXAMPLE @@ -2,14 +2,13 @@ Description=Moshing Mammut [Service] -ExecStart=/PATH_TO_MOSHING_MAMMUT/start.sh +ExecStart=/home/moshing-mammut/app/start.sh Restart=always -User=MOSHING_MAMMUT_USER -Group=nogroup +User=moshing-mammut +Group=moshing-mammut Environment=PATH=/usr/bin:/usr/local/bin Environment=NODE_ENV=production -WorkingDirectory=/PATH_TO_MOSHING_MAMMUT/ -KillMode=process +WorkingDirectory=/home/moshing-mammut/app [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/start.sh.EXAMPLE b/start.sh.EXAMPLE index 7ea8309..a620e80 100644 --- a/start.sh.EXAMPLE +++ b/start.sh.EXAMPLE @@ -1,3 +1,3 @@ #!/bin/bash -. /PATH_TO_YOUR_NVM/.nvm/nvm.sh +. /home/moshing-mammut/.nvm/nvm.sh node -r dotenv/config build \ No newline at end of file