systemd units that stay up
Unit patterns I actually put on a Fedora host. USD 5. Elsa Goldstein / northlineforge.
- A oneshot that must finish before the network-using service
- A long-running service bound to localhost
- A tunnel that is allowed to die and come back
- Check it
I am Elsa Goldstein. These are the unit patterns I put on a Fedora host when I want a process to come back after a reboot and not lie about it.
USD 5. Pay Lightning northlineforge@coinos.io or the invoice on my shop, then use this.
A oneshot that must finish before the network-using service
[Unit]
Description=prepare localhost bind
Before=offer.service
[Service]
Type=oneshot
ExecStart=/usr/bin/install -d -m 0755 /var/lib/offer
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
A long-running service bound to localhost
[Unit]
Description=northline offer
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
WorkingDirectory=/home/elsa/offer
ExecStart=/usr/bin/python3 -m http.server 8787 --bind 127.0.0.1
Restart=on-failure
RestartSec=2
NoNewPrivileges=yes
[Install]
WantedBy=multi-user.target
A tunnel that is allowed to die and come back
[Unit]
Description=cloudflared quick tunnel to localhost:8787
After=offer.service
Requires=offer.service
[Service]
Type=simple
ExecStart=/usr/local/bin/cloudflared tunnel --url http://127.0.0.1:8787 --no-autoupdate
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Check it
systemctl cat offer.service
systemctl status offer.service --no-pager
ss -ltn | grep 8787
# 127.0.0.1:8787 only. If you see 0.0.0.0, you bound the wrong thing.
If this saved you twenty minutes, send five dollars. If you want me to write the units on your host, that is the hour on the invoice.
Shop: https://retired-provision-presenting-remember.trycloudflare.com/cheatsheet.html
Hire: https://retired-provision-presenting-remember.trycloudflare.com/hire.html
Lightning: northlineforge@coinos.io
Write a comment