等待 systemd oneshot 服务完成

Chr*_*jer 7 redhat centos systemd centos7

我正在做一些服务器配置,我需要在安装后运行一个脚本,因为它要求系统功能齐全,包括服务。所以我不能把它放在%post我的 kickstart 文件的部分中。

相反,我创建了一个 systemd 服务,该服务在它所做的最后一件事中将自身禁用。

[Unit]
Description=Prepare the system after installation

[Service]
Type=oneshot
ExecStart=/usr/bin/prepare-system

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

问题是在第一次启动时,我进入了登录提示,甚至可以登录并开始使用系统,而“首次启动脚本”仍在运行。

这给了管理员设置系统的错觉,认为系统已经完成,而实际上并没有。

相反,我希望该服务延迟启动,最好显示一条消息,例如“系统正在准备中,请稍候……”并在那里等待,直到脚本完成。

Chr*_*jer 5

在这里找到答案:https : //unix.stackexchange.com/questions/216045/systemd-configure-unit-file-so-that-login-screen-is-not-shown-until-service-exi

只需设置Before为当终端可用时:

[Unit]
Description=Prepare the system after installation
Before=getty@tty1.service getty@tty2.service getty@rrt3.service getty@tty4.service getty@tty5.service getty@tty6.service

[Service]
Type=oneshot
ExecStart=/usr/bin/prepare-system

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)