Skip to content

Commit

Permalink
chore: update sample systemd units
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraichen committed Mar 20, 2023
1 parent 69d6938 commit 0343ee5
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 11 deletions.
14 changes: 7 additions & 7 deletions examples/systemd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Mnemosyne has been deployed a systemd services running a user session.

The web application runs with puma and systemd socket activation.

```
```plain
puma.socket
puma.service
```
Expand All @@ -15,7 +15,7 @@ puma.service

Consumers are started via a systemd target to allow simple sharing.

```
```plain
[email protected]
hutch.target
```
Expand All @@ -24,22 +24,22 @@ hutch.target

Create more services by enabling and starting service instances:

```
systemctl --user enable hutch@{1,2,3,4}.service
systemctl --user start hutch@{1,2,3,4}.service
```plain
systemctl --user enable hutch@{1,2}.service
systemctl --user start hutch@{1,2}.service
```

All services can be managed via the target, e.g.:

```
```plain
systemctl --user restart hutch.target
```

## Cleanup

The cleanup task is regularly run via a systemd timer and service.

```
```plain
mnemosyne-clean.timer
mnemosyne-clean.service
```
11 changes: 10 additions & 1 deletion examples/systemd/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ PartOf=hutch.target

[Service]
Type=simple

# Specify the path to your puma application root
Environment=RAILS_ENV=production
Environment=LOG_LEVEL=info
Environment=MALLOC_ARENA_MAX=2
Environment=JOB_INDEX=%i
EnvironmentFile=/home/mnemosyne/.config/default/mnemosyne
WorkingDirectory=/home/mnemosyne/application/current
ExecStart=/usr/bin/bundle exec rake mnemosyne:consume
ExecStart=/home/mnemosyne/application/current/bin/rake mnemosyne:consume
Restart=always
RestartSec=120
RuntimeMaxSec=24h
StandardOutput=null

[Install]
WantedBy=hutch.target
6 changes: 6 additions & 0 deletions examples/systemd/mnemosyne-clean.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ Description=Mnemosyne cleanup task

[Service]
Type=simple

Environment=RAILS_ENV=production
Environment=MALLOC_ARENA_MAX=2
EnvironmentFile=/home/mnemosyne/.config/default/mnemosyne

WorkingDirectory=/home/mnemosyne/application/current

ExecStart=/home/mnemosyne/application/current/bin/rake mnemosyne:clean

Restart=on-failure
RestartSec=60s

Expand Down
1 change: 1 addition & 0 deletions examples/systemd/mnemosyne-clean.timer
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Description=Run menmosyne clean up task removing data according to retention pol
[Timer]
OnCalendar=*-*-* 00:00:00
Unit=mnemosyne-clean.service
RandomizedDelaySec=2h

[Install]
WantedBy=timers.target
14 changes: 12 additions & 2 deletions examples/systemd/puma.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@
Description=Puma HTTP Server
After=network.target
Requires=puma.socket
Conflicts=unicorn.service

[Service]
Type=simple

Environment=LISTEN=unix:///tmp/mnemosyne/web.sock
Environment=MALLOC_ARENA_MAX=2
Environment=RAILS_ENV=production
Environment=RAILS_MAX_THREADS=32
Environment=WEB_CONCURRENCY=4
EnvironmentFile=/home/mnemosyne/.config/default/mnemosyne

WorkingDirectory=/home/mnemosyne/application/current
ExecStart=/home/mnemosyne/application/current/bin/puma -C config/puma.rb -w 3 -t 8:32 -b unix:///tmp/mnemosyne/puma.socket
Restart=always

ExecStart=/home/mnemosyne/application/current/bin/puma -C config/puma.rb -b ${LISTEN}

Restart=on-failure
RestartSec=10s

[Install]
WantedBy=default.target
3 changes: 2 additions & 1 deletion examples/systemd/puma.socket
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[Unit]
Description=Puma Socket
Conflicts=unicorn.socket

[Socket]
ListenStream=/tmp/mnemosyne/puma.socket
ListenStream=/tmp/mnemosyne/web.sock

NoDelay=true
ReusePort=true
Expand Down
27 changes: 27 additions & 0 deletions examples/systemd/unicorn.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Unit]
Description=Unicorn HTTP Server
After=network.target
Requires=unicorn.socket
Conflicts=puma.service

[Service]
Type=simple

Environment=LISTEN=/tmp/mnemosyne/web.sock
Environment=MALLOC_ARENA_MAX=2
Environment=RAILS_ENV=production
Environment=RAILS_MAX_THREADS=1
Environment=WORKER=8
EnvironmentFile=/home/mnemosyne/.config/default/mnemosyne

WorkingDirectory=/home/mnemosyne/application/current/

ExecStart=/home/mnemosyne/application/current/bin/unicorn --config-file config/unicorn.rb --listen ${LISTEN}
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -QUIT $MAINPID

Restart=on-failure
RestartSec=10s

[Install]
WantedBy=default.target
13 changes: 13 additions & 0 deletions examples/systemd/unicorn.socket
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Unicorn Socket
Conflicts=puma.socket

[Socket]
ListenStream=/tmp/mnemosyne/web.sock

NoDelay=true
ReusePort=true
Backlog=1024

[Install]
WantedBy=sockets.target

0 comments on commit 0343ee5

Please sign in to comment.