Skip to content

Commit

Permalink
fb_systemd: make knob for mgmt of default target
Browse files Browse the repository at this point in the history
Summary:

Make knob for mgmt of default target, so that it's possible to opt out as needed

Differential Revision: D51510688

fbshipit-source-id: 7c1a0f44975b4aa49ebba0ff5d81700297412e87
  • Loading branch information
joshuamiller01 authored and facebook-github-bot committed Nov 29, 2023
1 parent d1b1a92 commit 83c704a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cookbooks/fb_systemd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Attributes
* node['fb_systemd']['tmpfiles_excluded_prefixes']
* node['fb_systemd']['preset']
* node['fb_systemd']['manage_systemd_packages']
* node['fb_systemd']['manage_default_target']
* node['fb_systemd']['boot']['enable']
* node['fb_systemd']['boot']['path']
* node['fb_systemd']['boot']['loader']
Expand Down Expand Up @@ -408,6 +409,11 @@ By default this cookbook keeps the systemd packages up-to-date, but if you
want to manage them locally, simply set
`node['fb_systemd']['manage_systemd_packages']` to false.

### Default target
By default this cookbook manages the default systemd target, but if you
want otherwise, set
`node['fb_systemd']['manage_default_target']` to false.

### Boot
You can choose whether or not to enable `systemd-boot` with the
`node['fb_systemd']['boot']['enable']` attribute, which defaults to `false`.
Expand Down
1 change: 1 addition & 0 deletions cookbooks/fb_systemd/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
'tmpfiles_excluded_prefixes' => [],
'preset' => {},
'manage_systemd_packages' => true,
'manage_default_target' => true,
'boot' => {
'enable' => false,
'path' => esp_path,
Expand Down
3 changes: 3 additions & 0 deletions cookbooks/fb_systemd/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@
end

directory '/etc/systemd/user/default.target.wants' do
only_if { node['fb_systemd']['manage_default_target'] }
owner 'root'
group 'root'
mode '0755'
end

execute 'set default target' do
only_if { node['fb_systemd']['manage_default_target'] }
only_if do
current = shell_out('systemctl get-default').stdout.strip
is_ignored = node['fb_systemd']['ignore_targets'].include?(current)
Expand All @@ -173,6 +175,7 @@
end

link '/etc/systemd/system/default.target' do
only_if { node['fb_systemd']['manage_default_target'] }
only_if do
FB::Version.new(node['packages']['systemd'][
'version']) < FB::Version.new('205')
Expand Down
12 changes: 12 additions & 0 deletions cookbooks/fb_systemd/spec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@
tc.fixture('system.conf'),
)
end

it 'should skip default target when manage_default_target is false' do
chef_run.converge(described_recipe) do |node|
node.default['fb_systemd']['manage_default_target'] = false
end
expect(chef_run).not_to run_execute('set default target')
end

it 'should set default target when manage_default_target is true' do
chef_run.converge(described_recipe)
expect(chef_run).not_to run_execute('set default target')
end
end

0 comments on commit 83c704a

Please sign in to comment.