Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am looking for a way to instruct systemd to recalculate service dependencies while the system is booting. Specifically, I need one service to be able to enable another service, and have the second service start up later in the same boot sequence. This is part of my automatic deployment process; very early in the boot process, the first time the system starts up, it automatically configures itself. One of the steps that it may need to take is enabling other services. Unfortunately, any changes it makes at that step do not seem to take effect until the following reboot. Rebooting the machine after initial deployment is not an option.

Here's a generalized idea of what I'm trying to achieve

/etc/systemd/system/firstboot.service:

[Unit]
Description=Enable MyService
DefaultDependencies=no
After=sysinit.target
Before=basic.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl enable myservice.service
ExecStartPost=/bin/systemctl disable firstboot.service

[Install]
RequiredBy=basic.target

/etc/systemd/system/myservice.service:

[Unit]
Description=MyService

[Service]
Type=simple
ExecStart=/usr/local/bin/myservice

[Install]
WantedBy=multi-user.target

Unfortunately, this doesn't work as I expected; the service is enabled, but is not started before multi-user.target:

$ systemctl status myservice
myservice.service - MyService
   Loaded: loaded (/etc/systemd/system/myservice.service; enabled)
   Active: inactive (dead)

I can force it to start with systemctl isolate multi-user.target or by rebooting the machine.

I have tried adding systemctl daemon-reload and/or systemctl daemon-reexec to ExecStart/ExecStartPost of firstboot.service, but neither seem to have any effect.

Is there any way I can tell systemd to recalculate the boot path and include the changes that were made while it was still booting? Or will I need to do something later in the boot process to force my service to start?

share|improve this question
1  
systemd already does this by default - after a fashion - if you have it in initramfs. It execs itself at switchroot. If I were you I would have one initramfs for deployment and one it deploys. If you find the idea interesting look here for more: freedesktop.org/wiki/Software/systemd/InitrdInterface –  mikeserv Jun 6 at 14:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.