added systemd service howto
This commit is contained in:
78
README.md
78
README.md
@@ -125,15 +125,83 @@ For an enhanced tactile experience, Nexus Timer supports Smart Buttons based on
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
## Building for the production
|
## Building for the production
|
||||||
Build the docker image:
|
Clone the repo
|
||||||
```bash
|
```bash
|
||||||
docker build -t nexus-timer .
|
git clone --depth 1 https://gitea.virtonline.eu/2HoursProject/nexus-timer.git
|
||||||
|
cd nexus-timer
|
||||||
```
|
```
|
||||||
Run the app in the container:
|
Build the docker image
|
||||||
```bash
|
```bash
|
||||||
docker run --rm -p 8080:80 nexus-timer
|
docker build -t virt-nexus-timer .
|
||||||
```
|
```
|
||||||
Test the web app:
|
Do some sanity check first: Run the app in the container
|
||||||
|
```bash
|
||||||
|
docker run --rm -p 8080:80 virt-nexus-timer
|
||||||
|
```
|
||||||
|
Test the web app
|
||||||
```bash
|
```bash
|
||||||
curl http://localhost:8080/
|
curl http://localhost:8080/
|
||||||
```
|
```
|
||||||
|
## Expose the app on Internet behind the reverse proxy (Traefik)
|
||||||
|
Create the systemd service file
|
||||||
|
```bash
|
||||||
|
sudo systemctl edit --force --full virt-nexus-timer.service
|
||||||
|
```
|
||||||
|
File editor will open. Insert the service definition bellow then save and exit.
|
||||||
|
```bash
|
||||||
|
[Unit]
|
||||||
|
Description=nexus-timer (virt-nexus-timer)
|
||||||
|
Requires=docker.service
|
||||||
|
After=docker.service
|
||||||
|
DefaultDependencies=no
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Environment="HOME=/root"
|
||||||
|
ExecStartPre=-/usr/bin/env sh -c '/usr/bin/env docker kill virt-nexus-timer 2>/dev/null || true'
|
||||||
|
ExecStartPre=-/usr/bin/env sh -c '/usr/bin/env docker rm virt-nexus-timer 2>/dev/null || true'
|
||||||
|
|
||||||
|
ExecStart=/usr/bin/env docker run \
|
||||||
|
--rm \
|
||||||
|
--name=virt-nexus-timer \
|
||||||
|
--cap-drop=ALL \
|
||||||
|
--read-only \
|
||||||
|
--user=997:1002 \
|
||||||
|
--log-driver=none \
|
||||||
|
--network=traefik \
|
||||||
|
--label 'traefik.enable=true' \
|
||||||
|
--label 'traefik.docker.network=traefik' \
|
||||||
|
--label 'traefik.http.routers.virt-nexus-timer.rule=Host("nexus-timer.virtonline.eu")' \
|
||||||
|
--label 'traefik.http.routers.virt-nexus-timer.service=virt-nexus-timer' \
|
||||||
|
--label 'traefik.http.routers.virt-nexus-timer.tls=true' \
|
||||||
|
--label 'traefik.http.routers.virt-nexus-timer.tls.certResolver=default' \
|
||||||
|
--label 'traefik.http.routers.virt-nexus-timer.entrypoints=web-secure' \
|
||||||
|
--label 'traefik.http.services.virt-nexus-timer.loadbalancer.server.port=80' \
|
||||||
|
virt-nexus-timer
|
||||||
|
|
||||||
|
ExecStop=-/usr/bin/env sh -c '/usr/bin/env docker kill virt-nexus-timer 2>/dev/null || true'
|
||||||
|
ExecStop=-/usr/bin/env sh -c '/usr/bin/env docker rm virt-nexus-timer 2>/dev/null || true'
|
||||||
|
|
||||||
|
Restart=always
|
||||||
|
RestartSec=30
|
||||||
|
SyslogIdentifier=virt-nexus-timer
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
Enable the app to start when the server boots and start it now
|
||||||
|
```bash
|
||||||
|
sudo systemctl enable --now virt-nexus-timer.service
|
||||||
|
```
|
||||||
|
See the service status
|
||||||
|
```bash
|
||||||
|
systemctl status virt-nexus-timer.service
|
||||||
|
```
|
||||||
|
See the logs
|
||||||
|
```bash
|
||||||
|
journalctl -fu virt-nexus-timer.service
|
||||||
|
```
|
||||||
|
Finally test the web app
|
||||||
|
```bash
|
||||||
|
curl https://nexus-timer.virtonline.eu
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user