8

Sometimes I make a new unit in mistake, and then I have to go to /etc/systemd to look for the unit and delete all of its associated files/scripts/links/etc.

Is there a better way? Like a single command that deletes everything associated with a unit name?

3
  • 2
    What exactly do you mean with "associated files/scripts/links/etc."? Dec 14, 2013 at 23:08
  • @EliasProbst the files and symbol links systemd creates automatically after I run systemd enable <service_name>.
    – Howard
    Dec 16, 2013 at 9:14
  • Which distribution?
    – Nils
    Dec 19, 2013 at 16:37

2 Answers 2

4
+50

Like a single command that deletes everything associated with a unit name?

I think you need two commands, one to dissociate the unit and one to erase the unit file.

the files and symbol links systemd creates automatically after I run systemd enable

You mean systemctl enable .... Anyway, from man systemctl:

disable [NAME...]

Disables one or more units. This removes all symlinks to the specified unit files from the unit configuration directory, and hence undoes the changes made by enable. Note however that this removes all symlinks to the unit files (i.e. including manual additions), not just those actually created by enable. This call implicitly reloads the systemd daemon configuration after completing the disabling of the units. Note that this command does not implicitly stop the units that is being disabled.

The symlinks are there to associate the unit with a target -- this is the same as the symlinks used in sysV rcN.d runlevel directories.1 Disabling a unit removes those, since they are what "enable" it be run with whatever target(s).

Once those are gone, the only thing that is left is the .service file you presumably created. Erase/remove that and you're done.


1. To be clear: you're not using sysV so if that observation meant nothing to you, don't worry about it. There may be /etc/rcN.d directories on your system, ignore them.

0
-1

insserv should do that job - no matter if sysVinit or systemD.

Reference: OpenSuSE

Example: insserv -d nfs disables the startup of the nfs service.

2
  • 1
    What do you mean? Is using insserv a way to delete a unit in systemd? Could you give an example?
    – Neil
    Feb 12, 2016 at 18:19
  • @Neil I updated my answer with an example.
    – Nils
    Feb 13, 2016 at 19:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .