-
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
3 changed files
with
79 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
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
<%# | ||
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 /tmp/first_boot_script.sh | ||
RemainAfterExit=true | ||
Type=oneshot | ||
ExecStartPost=/usr/bin/systemctl disable first_boot_service | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
<%# | ||
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) | ||
initd_script = """ | ||
#! /bin/bash | ||
|
||
### BEGIN INIT INFO | ||
# Provides: foo | ||
# Required-Start: $local_fs $network | ||
# Required-Stop: $local_fs | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: foo service | ||
# Description: Run Foo service | ||
### 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 $? | ||
""" | ||
%> | ||
<% if has_systemd -%> | ||
<%= save_to_file('/etc/systemd/system/first_boot_service.service', snippet('first_boot_service')) %> | ||
<%= save_to_file('/tmp/first_boot_script', snippet('built', :variables => { :endpoint => 'built', :method => 'POST', :body_file => '/root/install.post.log' })) %> | ||
systemctl enable first_boot_service | ||
chmod +x /tmp/first_boot_script | ||
<% else %> | ||
<%= save_to_file('/tmp/first_boot_script', snippet('built', :variables => { :endpoint => 'built', :method => 'POST', :body_file => '/root/install.post.log' }) + | ||
"\nmv /tmp/first_boot_script /tmp/first_boot_script.disabled") %> | ||
<%= save_to_file('/etc/init.d/first_boot_setup', initd_script) %> | ||
chmod +x /tmp/first_boot_script | ||
chmod +x /etc/init.d/first_boot_setup | ||
chkconfig --add /etc/init.d/first_boot_setup | ||
chkconfig --level 2345 first_boot_setup on | ||
<% end %> |