[systemd-devel] How to permanently disable a service after first boot

Mathieu Bridon bochecha at fedoraproject.org
Fri Sep 27 00:50:18 PDT 2013


Hi,

On Fri, 2013-09-27 at 12:26 +0500, Muhammad Shakeel wrote:
> If there is a foo.service which is required to run during first system 
> boot then what is the best solution to permanently disable it afterwards?
> 
> I can think of two solutions but I am not sure which one is correct/more 
> appropriate.
> 
> 1) ExecStartPost=systemctl disable foo.service (I doubt this will work)

You should have tried it, it actually does work. :)

> Is there any flag in for systemd unit files which can be set to run a 
> service on first boot only?

Another way is to have a ConditionFileExists=!/path/to/file pointing to
a file created by the service the first time it runs.

That's how I run initialization of PostgreSQL instances at first boot:

  $ cat /lib/systemd/system/postgresql-setup-stage1.service
  [Unit]
  ...
  ConditionPathExists=!/var/lib/pgsql/data/PG_VERSION
  ...

  [Service]
  Type=oneshot
  ExecStart=/usr/bin/postgresql-setup initdb
  RemainAfterExit=true

The postgresql-setup script will create the file on the first run, and
as a result the service is never run any more.


-- 
Mathieu



More information about the systemd-devel mailing list