[Ubuntu] Add or remove a systemctl (systemd) service
An example to add or remove a service on system with systemd
Add
-
Create a file in
/lib/systemd/system/<service_name>.service
replace
with real name, without space [Unit] Description=Do Something Service After=network.target [Service] Type=simple ExecStart=/path/to/execution/file_or_execute_script Restart=always RestartSec=3 RemainAfterExit=yes [Install] WantedBy=multi-user.target
-
Update
systemctl
and start service:replace
with real name, without space systemctl daemon-reload systemctl enable <service_name>.service service <service_name> start service <service_name> status
Remove
replace
with real name, without space
systemctl stop <service_name>
systemctl disable <service_name>
rm /lib/systemd/system/<service_name>.service
systemctl daemon-reload
systemctl reset-failed