[CentOS] centos 7- boot doesn't wait for startup script to complete

Jonathan Billings billings at negate.org
Mon May 15 17:28:13 UTC 2017


On Mon, May 15, 2017 at 04:07:35PM +0000, KM wrote:
> Hello,Nothing I have found has solved this issue.  the service
> starts on boot, but the booting process continues.  When I log in my
> startup script is still running and finishes up.  that is good at
> least, but I'd still like to know how to make it wait. 
> Any feedback is appreciated. Thanks in advance.KM

Your systemd service unit is behaving as it would if you didn't
specify that user logins couldn't happen until the service had
finished.

I've done something like this by using a systemd unit that looks like
this: (it's a trivial sleep, but you get the idea)




# systemctl cat waitcommand.service 
# /etc/systemd/system/waitcommand.service
[Unit]
Description=Wait 120 seconds
Before=systemd-user-sessions.service

[Service]
Type=oneshot
ExecStartPre=/usr/bin/sleep 120
ExecStart=/usr/bin/logger "Wait finished"
TimeoutStartSec=125s
KillMode=process

[Install]
WantedBy=multi-user.target





If you try to SSH into the host, you'll get an error like this until
the service completes:

$ ssh my host
System is booting up. See pam_nologin(8)
Authentication failed.
$ 

The reason why I have the ExecStartPre is because the service won't be
considered "started" until the ExecStartPre command finishes and the
ExecStart can run.  The unit says that it runs before
systemd-user-sessions.service, which is what prevents user logins (and
shows the pam_nologin prompt) until it starts.  I also set a timeout
with a bit longer than the expected time to run.  Once my service is
started, then user sessions can
start. 

Kinda hacky but it probably will work for you.

-- 
Jonathan Billings <billings at negate.org>



More information about the CentOS mailing list