Generated image
|| #resource #automation

Simple Startup Script

Setting up a simple service with SystemD

Problem

Create a service in systemd that gets run once on startup.

Solution

1. Create Service File

[Unit]
Description=My Test Script
After=syslog.target
After=network.target

[Service]
Type=oneshot
User=root
Group=root
WorkingDirectory=/root
ExecStart=/path/to/my-script.sh
Environment=USER=root HOME=/root

[Install]
WantedBy=multi-user.target

The snippet above will run the /path/to/my-script.sh as the root user on system startup and will only run it once.

2. Reload services

This command will tell systemd to reload all the service files and detect the new file.

systemctl daemon-reload

3. Enable Service

And this command will enable the service, instructing systemd to run it at startup.

systemctl enable file-name-of-my-service.service

Maybe try another one?

Markdown Reference Everything you need to know to get started with Markdown ⌨️
2020.10.15
Markdown: Nested Code Block How to render a markdown code block inside another
2020.10.19
Convert WEBP to JPG Quickly convert WEBP images to a more standard JPG format
2022.09.13