[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Insert a script into systemd boot order at a specific location



Hello,

> According to
> http://www.freedesktop.org/software/systemd/man/systemd.unit.html you
> can specify "After=" and "Before=" in order to force your unit to start
> in a specified position. The documentation suggests that you typically
> list your "After=" units also in "Requires=" so that starting your unit
> causes the "After=" units to be started too (but, presumably, if they're
> optional, you wouldn't do that).

As a first attempt, I created a file /lib/systemd/system/script.service,
looking like this:

[Unit]
Description=Execute startup script
Before=multi-user.target
After=basic.target

[Service]
ExecStart=/usr/sbin/script
Type=oneshot

[Install]
RequiredBy=multi-user.target


Then, I called

systemctl enable script.service

Then, I rebooted, and my script was executed, but though I had defined it
to be executed before multi-user, for example gdm was started before my
script was finished.

So, I changed script.service:

[Unit]
Description=Execute startup script

[Service]
ExecStart=/usr/sbin/script
Type=oneshot

[Install]
RequiredBy=script.target

and created a new script.target:

[Unit]
Description=Installation and configuration
Requires=basic.target
Before=multi-user.target
After=basic.target

[Install]
RequiredBy=multi-user.target

Then, I called systemctl to set the correct symlinks for script.target and
script.service.

Then, I rebooted again and the result was the same as before.

Why does systemd not follow these instructions that my script has to be
executed before multi-user?

Regards
  Christoph


Reply to: