How To Remove Systemd Service

The correct way to remove systemd service.

Method

1
2
3
4
5
6
systemctl stop [servicename]
systemctl disable [servicename]
rm /your/service/locations/[servicename]
rm /your/service/locations/[servicename] # and symlinks that might be related
systemctl daemon-reload
systemctl reset-failed

Systemd uses unit (file to define services) to remove a service the unit have to be removed… here is a list of unit locations :1

1
2
3
4
5
6
/etc/systemd/system/ (and sub directories)
/usr/local/etc/systemd/system/ (and sub directories)
~/.config/systemd/user/ (and sub directories)
/usr/lib/systemd/ (and sub directories)
/usr/local/lib/systemd/ (and sub directories)
/etc/init.d/ (Converted old service system)

You can easily find location in loaded property using systemctl status [service]

1
2
3
4
5
$ systemctl status bluetooth.service
 bluetooth.service - Bluetooth service
  Loaded: loaded (/lib/systemd/system/bluetooth.service; disabled; vendor preset: enabled)
  Active: inactive (dead)
    Docs: man:bluetoothd(8)

Or using systemctl cat [service]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# systemctl cat frps.service
# /lib/systemd/system/frps.service
[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frps -c /etc/frp/frps.ini

[Install]
WantedBy=multi-user.target

About “reset-failed” Option

From the systemd man page:

reset-failed [PATTERN…]

Reset the “failed” state of the specified units, or if no unit name is passed, reset the state of all units. When a unit fails in some way (i.e. process exiting with non-zero error code, terminating abnormally or timing out), it will automatically enter the “failed” state and its exit code and status is recorded for introspection by the administrator until the service is restarted or reset with this command.

Reference

使用 Hugo 构建
主题 StackJimmy 设计