Tutoriel pour créer un service systemd robuste pour vos applications en 2026.
Voir notre guide systemd timers.
Service simple
# /etc/systemd/system/myapp.service
[Unit]
Description=My Bun API
After=network.target postgresql.service
Requires=postgresql.service
[Service]
Type=simple
User=myapp
Group=myapp
WorkingDirectory=/opt/myapp
EnvironmentFile=/opt/myapp/.env
ExecStart=/usr/local/bin/bun run start
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
# Hardening
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/opt/myapp/uploads
ProtectKernelTunables=true
RestrictAddressFamilies=AF_INET AF_INET6
LockPersonality=true
# Limits
MemoryMax=512M
CPUQuota=80%
[Install]
WantedBy=multi-user.targetActiver
systemctl daemon-reload
systemctl enable --now myapp
systemctl status myapp
journalctl -u myapp -fType=oneshot pour scripts
Pour un script qui finit après exécution (backup, cron-like) : Type=oneshot + RemainAfterExit=no.
Type=notify pour app moderne
Si votre app supporte sd_notify (Coolify, Caddy, Postgres) : Type=notify. systemd considère le service « actif » seulement quand l’app envoie son ready signal.