Systemd Service
Template for creating a systemd service unit that runs a script at boot.
Setup
- Create a
.servicefile in/etc/systemd/system/:
[Unit]
Description=Run Azure DevOps backup script at startup
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
User=sean
Group=sean
WorkingDirectory=/home/sean/devops-backup/
Environment=AZURE_DEVOPS_PAT=<PAT>
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ExecStart=/home/sean/devops-backup/backup-azure-devops.sh
StandardOutput=append:/var/log/myscript.log
StandardError=append:/var/log/myscript.log
[Install]
WantedBy=multi-user.target- Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable your-service.service
sudo systemctl start your-service.serviceKey fields
Type=oneshot— Script runs once and exits (not a daemon)After=network-online.target— Waits for network before runningEnvironment— Set environment variables the script needsStandardOutput/StandardError— Redirect logs to a fileWantedBy=multi-user.target— Runs at normal boot (multi-user mode)
Last updated on