Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let podman write the unit files #80

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions manifests/container.pp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
if $user != undef and $user != '' {
$systemctl = 'systemctl --user '
$requires = [Podman::Rootless[$user], Service['podman systemd-logind']]
$service_unit_file = "${User[$user]['home']}/.config/systemd/user/podman-${container_name}.service"
$service_unit_file = "${User[$user]['home']}/.config/systemd/user/container-${container_name}.service"
$_podman_systemd_reload = Exec["podman_systemd_${user}_reload"]

# The handle is used to ensure resources have unique names
Expand Down Expand Up @@ -139,7 +139,7 @@
} else {
$systemctl = 'systemctl '
$requires = []
$service_unit_file = "/etc/systemd/system/podman-${container_name}.service"
$service_unit_file = "/etc/systemd/system/container-${container_name}.service"
$_podman_systemd_reload = Exec['podman_systemd_reload']
$handle = $container_name
$exec_defaults = {}
Expand Down Expand Up @@ -242,7 +242,7 @@
}

$command_prc = @("END"/L)
${systemctl} stop podman-${container_name} || true
${systemctl} stop container-${container_name} || true
podman container stop --time 60 ${container_name} || true
podman container rm --force ${container_name} || true
| END
Expand Down Expand Up @@ -323,13 +323,13 @@
}

$command_sp = @("END"/L)
${systemctl} ${startup} podman-${container_name}.service
${systemctl} ${action} podman-${container_name}.service
${systemctl} ${startup} container-${container_name}.service
${systemctl} ${action} container-${container_name}.service
| END

$unless_sp = @("END"/L)
${systemctl} is-active podman-${container_name}.service && \
${systemctl} is-enabled podman-${container_name}.service
${systemctl} is-active container-${container_name}.service && \
${systemctl} is-enabled container-${container_name}.service
| END

exec { "service_podman_${handle}":
Expand All @@ -342,9 +342,10 @@
} else {
exec { "podman_generate_service_${handle}":
path => '/sbin:/usr/sbin:/bin:/usr/bin',
command => "podman generate systemd ${_service_flags} ${container_name} > ${service_unit_file}",
command => "podman generate systemd --files --name ${_service_flags} ${container_name}",
cwd => '/etc/systemd/system',
refreshonly => true,
notify => Service["podman-${handle}"],
notify => Service["container-${handle}"],
}

# Configure the container service per parameters
Expand All @@ -353,21 +354,21 @@
} else {
$state = 'stopped'; $startup = 'false'
}
service { "podman-${handle}":
service { "container-${handle}":
ensure => $state,
enable => $startup,
}
}
}
default: {
$command_sp = @("END"/L)
${systemctl} stop podman-${container_name}
${systemctl} disable podman-${container_name}
${systemctl} stop container-${container_name}
${systemctl} disable container-${container_name}
| END

$onlyif_sp = @("END"/$L)
test "\$(${systemctl} is-active podman-${container_name} 2>&1)" = "active" -o \
"\$(${systemctl} is-enabled podman-${container_name} 2>&1)" = "enabled"
test "\$(${systemctl} is-active container-${container_name} 2>&1)" = "active" -o \
"\$(${systemctl} is-enabled container-${container_name} 2>&1)" = "enabled"
| END

exec { "service_podman_${handle}":
Expand Down
45 changes: 24 additions & 21 deletions spec/defines/container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
end

remove_command = <<-END.gsub(%r{^\s+\|}, '')
|systemctl stop podman-namevar || true
|systemctl stop container-namevar || true
|podman container stop --time 60 namevar || true
|podman container rm --force namevar || true
END
Expand Down Expand Up @@ -143,15 +143,16 @@
is_expected.to contain_exec('podman_generate_service_namevar').only_with(
{
'path' => '/sbin:/usr/sbin:/bin:/usr/bin',
'command' => 'podman generate systemd namevar > /etc/systemd/system/podman-namevar.service',
'command' => 'podman generate systemd --files --name namevar',
'cwd' => '/etc/systemd/system',
'refreshonly' => true,
'notify' => 'Service[podman-namevar]',
'notify' => 'Service[container-namevar]',
},
)
end

it do
is_expected.to contain_service('podman-namevar').only_with(
is_expected.to contain_service('container-namevar').only_with(
{
'ensure' => 'running',
'enable' => true,
Expand Down Expand Up @@ -326,7 +327,7 @@
it do
is_expected.to contain_exec('podman_generate_service_testing-namevar').only_with(
{
'command' => 'podman generate systemd namevar > /home/testing/.config/systemd/user/podman-namevar.service',
'command' => 'podman generate systemd namevar > /home/testing/.config/systemd/user/container-namevar.service',
'refreshonly' => true,
'notify' => 'Exec[service_podman_testing-namevar]',
'require' => ['Podman::Rootless[testing]', 'Service[podman systemd-logind]'],
Expand All @@ -341,8 +342,8 @@
it do
is_expected.to contain_exec('service_podman_testing-namevar').only_with(
{
'command' => "systemctl --user enable podman-namevar.service\nsystemctl --user start podman-namevar.service\n",
'unless' => "systemctl --user is-active podman-namevar.service && systemctl --user is-enabled podman-namevar.service\n",
'command' => "systemctl --user enable container-namevar.service\nsystemctl --user start container-namevar.service\n",
'unless' => "systemctl --user is-active container-namevar.service && systemctl --user is-enabled container-namevar.service\n",
'require' => ['Podman::Rootless[testing]', 'Service[podman systemd-logind]'],
'path' => '/sbin:/usr/sbin:/bin:/usr/bin',
'environment' => ['HOME=/home/testing', 'XDG_RUNTIME_DIR=/run/user/3333', 'DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/3333/bus'],
Expand Down Expand Up @@ -424,7 +425,7 @@
end

it do
is_expected.to contain_file('/home/testing/.config/systemd/user/podman-namevar.service').with(
is_expected.to contain_file('/home/testing/.config/systemd/user/container-namevar.service').with(
{
'require' => ['Podman::Rootless[testing]', 'Service[podman systemd-logind]', 'Exec[service_podman_testing-namevar]'],
},
Expand Down Expand Up @@ -460,7 +461,8 @@
it do
is_expected.to contain_exec('podman_generate_service_namevar').with(
{
'command' => 'podman generate systemd namevar > /etc/systemd/system/podman-namevar.service',
'command' => 'podman generate systemd --files --name namevar',
'cwd' => '/etc/systemd/system',
},
)
end
Expand Down Expand Up @@ -494,7 +496,8 @@
it do
is_expected.to contain_exec('podman_generate_service_namevar').with(
{
'command' => 'podman generate systemd namevar > /etc/systemd/system/podman-namevar.service',
'command' => 'podman generate systemd --files --name namevar',
'cwd' => '/etc/systemd/system',
},
)
end
Expand Down Expand Up @@ -539,16 +542,16 @@
it do
is_expected.to contain_exec('podman_generate_service_testing-namevar').with(
{
'command' => 'podman generate systemd namevar > /home/testing/.config/systemd/user/podman-namevar.service',
'command' => 'podman generate systemd namevar > /home/testing/.config/systemd/user/container-namevar.service',
},
)
end

it do
is_expected.to contain_exec('service_podman_testing-namevar').with(
{
'command' => "systemctl --user enable podman-namevar.service\nsystemctl --user start podman-namevar.service\n",
'unless' => "systemctl --user is-active podman-namevar.service && systemctl --user is-enabled podman-namevar.service\n",
'command' => "systemctl --user enable container-namevar.service\nsystemctl --user start container-namevar.service\n",
'unless' => "systemctl --user is-active container-namevar.service && systemctl --user is-enabled container-namevar.service\n",
},
)
end
Expand All @@ -574,8 +577,8 @@
it do
is_expected.to contain_exec('service_podman_namevar').only_with(
{
'command' => "systemctl stop podman-namevar\nsystemctl disable podman-namevar\n",
'onlyif' => "test \"$(systemctl is-active podman-namevar 2>&1)\" = \"active\" -o \"$(systemctl is-enabled podman-namevar 2>&1)\" = \"enabled\"\n",
'command' => "systemctl stop container-namevar\nsystemctl disable container-namevar\n",
'onlyif' => "test \"$(systemctl is-active container-namevar 2>&1)\" = \"active\" -o \"$(systemctl is-enabled container-namevar 2>&1)\" = \"enabled\"\n",
'notify' => 'Exec[podman_remove_container_namevar]',
'require' => [],
'path' => '/sbin:/usr/sbin:/bin:/usr/bin',
Expand Down Expand Up @@ -608,7 +611,7 @@
end

it do
is_expected.to contain_file('/etc/systemd/system/podman-namevar.service').only_with(
is_expected.to contain_file('/etc/systemd/system/container-namevar.service').only_with(
{
'ensure' => 'absent',
'require' => ['Exec[service_podman_namevar]'],
Expand Down Expand Up @@ -652,8 +655,8 @@
it do
is_expected.to contain_exec('service_podman_user-namevar').only_with(
{
'command' => "systemctl --user stop podman-namevar\nsystemctl --user disable podman-namevar\n",
'onlyif' => "test \"$(systemctl --user is-active podman-namevar 2>&1)\" = \"active\" -o \"$(systemctl --user is-enabled podman-namevar 2>&1)\" = \"enabled\"\n",
'command' => "systemctl --user stop container-namevar\nsystemctl --user disable container-namevar\n",
'onlyif' => "test \"$(systemctl --user is-active container-namevar 2>&1)\" = \"active\" -o \"$(systemctl --user is-enabled container-namevar 2>&1)\" = \"enabled\"\n",
'notify' => 'Exec[podman_remove_container_user-namevar]',
'require' => ['Podman::Rootless[user]', 'Service[podman systemd-logind]'],
'path' => '/sbin:/usr/sbin:/bin:/usr/bin',
Expand Down Expand Up @@ -695,7 +698,7 @@
end

it do
is_expected.to contain_file('/home/user/.config/systemd/user/podman-namevar.service').only_with(
is_expected.to contain_file('/home/user/.config/systemd/user/container-namevar.service').only_with(
{
'ensure' => 'absent',
'require' => ['Podman::Rootless[user]', 'Service[podman systemd-logind]', 'Exec[service_podman_user-namevar]'],
Expand All @@ -719,7 +722,7 @@
let(:pre_condition) { 'include podman' }

it do
is_expected.to contain_service('podman-namevar').only_with(
is_expected.to contain_service('container-namevar').only_with(
{
'ensure' => 'stopped',
'enable' => false,
Expand All @@ -746,7 +749,7 @@
it do
is_expected.to contain_exec('service_podman_user-namevar').with(
{
'command' => "systemctl --user disable podman-namevar.service\nsystemctl --user stop podman-namevar.service\n",
'command' => "systemctl --user disable container-namevar.service\nsystemctl --user stop container-namevar.service\n",
},
)
end
Expand Down