Startup Example#
systemctl start $name
# Start
systemctl stop $name
# Stop
systemctl enable $name
# Enable auto-start on boot
systemctl disable $name
# Disable auto-start on boot
Configuration File Example
[Unit] # This section is related to the explanation and service execution dependency of this unit
Description=OpenSSH server daemon
# Descriptive content
After=network.target
# After network startup
Wants=sshd-keygen.service
[Service] # This section is related to the actual command parameters executed
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install] # This section specifies which target this unit should be mounted under
WantedBy=multi-user.target
Excerpt from here#
I don't want to organize it, so I put it in an Excel file.
Configuration File Example for rssbot
[Unit]
Description=RSSBOT
After=network.target
[Service]
Type=simple
ExecStart=/root/rssbot/run.sh
Restart=always
[Install]
WantedBy=multi-user.target
systemd distinguishes between system and user; system files are located in /user/lib/systemd/system/, while user files are located in /etc/lib/systemd/user/.
It is recommended to store manually created unit files by system administrators in the /etc/systemd/system/ directory.
Notes:#
- Use absolute paths in [Service], for example, replace sh with /usr/bin/sh.
- systemctl status rssbot.service
View the status of the service. - systemctl daemon-reload
Refresh the service status.
That's it, just taking some notes.