Systemd deploy (#669)

* Added systemd config for deployment

* Add menu option.

* Update docs/deploy/systemd.md

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>

* Update docs/deploy/systemd.md

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>

* Update docs/deploy/systemd.md

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>

* Update docs/deploy/systemd.md

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>

* Added  stop, restart commands and more details on user to run them as

* Update docs/deploy/systemd.md

* Update docs/deploy/systemd.md

* Update docs/deploy/systemd.md

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
This commit is contained in:
Craig Avnit 2022-06-16 15:11:28 +01:00 committed by GitHub
parent 7f64579ab5
commit e548510681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 76 additions and 7 deletions

68
docs/deploy/systemd.md Normal file
View File

@ -0,0 +1,68 @@
# Systemd
Systemd is the default system and service manager on most Linux distributions. It is usually installed by default so no installation is needed on supported Swift distributions.
## Configure
Each Vapor app on your server should have its own service file. For an example `Hello` project, the configuration file would be located at `/etc/systemd/system/hello.service`. This file should look like the following:
```sh
[Unit]
Description=Hello
Requires=network.target
After=network.target
[Service]
Type=simple
User=vapor
Group=vapor
Restart=always
RestartSec=3
WorkingDirectory=/home/vapor/hello
ExecStart=/home/vapor/hello/.build/release/Run serve --env production
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=vapor-hello
[Install]
WantedBy=multi-user.target
```
As specified in our configuration file the `Hello` project is located in the home folder for the user `vapor`. Make sure `WorkingDirectory` points to the root directory of your project where the `Package.swift` file is.
The `--env production` flag will disable verbose logging.
### Environment
Otherwise, quoting the values is optional but recommended.
You can export variables in two ways via systemd. Either by creating an environment file with all the variables set in it:
```sh
EnvironmentFile=/path/to/environment/file1
EnvironmentFile=/path/to/environment/file2
```
Or you can add them directly to the service file under `[service]`:
```sh
Environment="PORT=8123"
Environment="ANOTHERVALUE=/something/else"
```
Exported variables can be used in Vapor using `Environment.get`
```swift
let port = Environment.get("PORT")
```
## Start
You can now load, enable, start, stop and restart your app by running the following as root.
```sh
systemctl daemon-reload
systemctl enable hello
systemctl start hello
systemctl stop hello
systemctl restart hello
```

View File

@ -23,7 +23,7 @@ theme:
palette:
primary: black
accent: blue
logo: assets/logo.png
favicon: assets/favicon.png
@ -31,10 +31,10 @@ theme:
- search.suggest
- search.highlight
# Customization
# Customization
extra:
# Font
font:
font:
text: Roboto Slab
code: Source Code Pro
@ -74,14 +74,14 @@ plugins:
material_alternate: true
# Add the new languages here. DON'T CHANGE THE DEFAULT LANGUAGE
languages:
en:
en:
name: English
build: true
zh:
name: 简体中文
site_name: Vapor 中文文档
build: true
nl:
nl:
name: Nederlands
site_name: Vapor Documentatie
build: true
@ -97,9 +97,9 @@ plugins:
nav_translations:
nl:
Welcome: Welkom
fr:
fr:
Welcome: Bienvenue
de:
de:
Welcome: Willkommen
zh:
Welcome: 序言
@ -210,6 +210,7 @@ nav:
- DigitalOcean: "deploy/digital-ocean.md"
- Heroku: "deploy/heroku.md"
- Supervisor: "deploy/supervisor.md"
- Systemd: "deploy/systemd.md"
- Nginx: "deploy/nginx.md"
- Docker: "deploy/docker.md"
- Version (4.0):