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?

How the Visitor Pattern Works Demonstrating the purpose of the visitor pattern using Java
2019.11.25
Docker: Use Container Env in Docker Exec How to use the container environment in a Docker Exec command
2021.05.09
Docker: Accessing Host Accessing the host machine from inside a docker container
2021.07.24