-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #35378 - Add systemd first boot service for host provisioning
- Loading branch information
Showing
4 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/views/unattended/provisioning_templates/snippet/first_boot_service.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<%# | ||
kind: snippet | ||
name: first_boot_service | ||
model: ProvisioningTemplate | ||
snippet: true | ||
description: | | ||
Post replacement service | ||
-%> | ||
[Unit] | ||
Description=Initial setup callback | ||
Wants=network-online.target | ||
After=network-online.target | ||
|
||
[Service] | ||
ExecStart=/bin/bash /root/first_boot_script.sh | ||
Type=oneshot | ||
ExecStartPost=/usr/bin/systemctl disable first_boot_service | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
29 changes: 29 additions & 0 deletions
29
app/views/unattended/provisioning_templates/snippet/first_boot_setup.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<%# | ||
kind: snippet | ||
name: first_boot_setup | ||
model: ProvisioningTemplate | ||
snippet: true | ||
description: | | ||
Post replacement for both systemd and non-systemd platforms | ||
-%> | ||
<% | ||
os_major = @host.operatingsystem.major.to_i | ||
rhel_compatible = @host.operatingsystem.family == 'Redhat' && @host.operatingsystem.name != 'Fedora' | ||
has_systemd = (@host.operatingsystem.name == 'Fedora' && os_major >= 20) || (rhel_compatible && os_major >= 7) || (@host.operatingsystem.name == 'Ubuntu' && os_major >= 15) || (@host.operatingsystem.name == 'Debian' && os_major >= 8) | ||
-%> | ||
<% if has_systemd -%> | ||
<%= save_to_file('/etc/systemd/system/first_boot_service.service', snippet('first_boot_service')) %> | ||
<%= save_to_file('/root/first_boot_script.sh', snippet('built', :variables => { :endpoint => 'built', :method => 'POST', :body_file => '/root/install.post.log' })) %> | ||
|
||
systemctl enable first_boot_service | ||
<% else -%> | ||
<%= save_to_file('/root/first_boot_script.sh', snippet('built', :variables => { :endpoint => 'built', :method => 'POST', :body_file => '/root/install.post.log' }) + | ||
"\nmv /root/first_boot_script.sh /root/first_boot_script.disabled") %> | ||
<%= save_to_file('/etc/init.d/first_boot_setup', snippet('first_boot_initd')) %> | ||
|
||
chmod +x /etc/init.d/first_boot_setup | ||
chkconfig --add /etc/init.d/first_boot_setup | ||
chkconfig --level 2345 first_boot_setup on | ||
<% end -%> | ||
|
||
chmod +x /root/first_boot_script.sh |
34 changes: 34 additions & 0 deletions
34
app/views/unattended/provisioning_templates/snippet/fist_boot_initd.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<%# | ||
kind: snippet | ||
name: first_boot_initd | ||
model: ProvisioningTemplate | ||
snippet: true | ||
description: | | ||
Post replacement initd script | ||
-%> | ||
#! /bin/bash | ||
|
||
### BEGIN INIT INFO | ||
# Provides: RedHat | ||
# Required-Start: $local_fs $network | ||
# Required-Stop: $local_fs | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: Execute first boot script | ||
# Description: Execute first boot script which executes after machine is successfully built for the first time. | ||
### END INIT INFO | ||
|
||
# Source function library | ||
. /etc/rc.d/init.d/functions | ||
|
||
##Service start/stop functions## | ||
start() { | ||
/tmp/first_boot_script | ||
chkconfig --del first_boot_setup | ||
} | ||
|
||
start | ||
|
||
exit 5 | ||
esac | ||
exit $? |