Skip to content

Commit 26317c3

Browse files
committed
Add loginctl_linger_users fact
1 parent 197a307 commit 26317c3

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lib/facter/loginctl_linger_users.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
# https://puppet.com/docs/puppet/latest/fact_overview.html
4+
Facter.add(:loginctl_linger_users) do
5+
confine kernel: 'Linux'
6+
7+
setcode do
8+
users = []
9+
10+
if Dir.exist?('/var/lib/systemd/linger')
11+
users = Dir.entries('/var/lib/systemd/linger')
12+
users.delete('.')
13+
users.delete('..')
14+
end
15+
16+
users.append('root') unless users.include?('root') # root should always linger
17+
18+
users
19+
end
20+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe Facter.fact(:loginctl_linger_users) do
6+
before do
7+
Facter.clear
8+
end
9+
10+
describe 'loginctl_linger_users' do
11+
context 'returns root when nothing is present' do
12+
before do
13+
allow(Dir).to receive(:exist?).with('/var/lib/systemd/linger').and_return(false)
14+
end
15+
16+
it do
17+
expect(Facter.value(:loginctl_linger_users)).to eq(['root'])
18+
end
19+
end
20+
21+
context 'returns list with root others are present' do
22+
before do
23+
allow(Dir).to receive(:exist?).with('/var/lib/systemd/linger').and_return(true)
24+
allow(Dir).to receive(:entries).with('/var/lib/systemd/linger').and_return(%w[. .. abc test])
25+
end
26+
27+
it do
28+
expect(Facter.value(:loginctl_linger_users)).to eq(%w[abc test root])
29+
end
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)