mirror of https://github.com/containers/podman.git
Restart all containers with restart-policy=always on boot
* Add podman-restart systemd unit file and add it to podman RPM package * Fix podman start to filter all containers + unit test Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
This commit is contained in:
parent
a2e1df80bc
commit
302b3084eb
2
Makefile
2
Makefile
|
@ -748,11 +748,13 @@ install.systemd:
|
||||||
install ${SELINUXOPT} -m 644 contrib/systemd/auto-update/podman-auto-update.timer ${DESTDIR}${USERSYSTEMDDIR}/podman-auto-update.timer
|
install ${SELINUXOPT} -m 644 contrib/systemd/auto-update/podman-auto-update.timer ${DESTDIR}${USERSYSTEMDDIR}/podman-auto-update.timer
|
||||||
install ${SELINUXOPT} -m 644 contrib/systemd/user/podman.socket ${DESTDIR}${USERSYSTEMDDIR}/podman.socket
|
install ${SELINUXOPT} -m 644 contrib/systemd/user/podman.socket ${DESTDIR}${USERSYSTEMDDIR}/podman.socket
|
||||||
install ${SELINUXOPT} -m 644 contrib/systemd/user/podman.service ${DESTDIR}${USERSYSTEMDDIR}/podman.service
|
install ${SELINUXOPT} -m 644 contrib/systemd/user/podman.service ${DESTDIR}${USERSYSTEMDDIR}/podman.service
|
||||||
|
install ${SELINUXOPT} -m 644 contrib/systemd/user/podman-restart.service ${DESTDIR}${USERSYSTEMDDIR}/podman-restart.service
|
||||||
# System services
|
# System services
|
||||||
install ${SELINUXOPT} -m 644 contrib/systemd/auto-update/podman-auto-update.service ${DESTDIR}${SYSTEMDDIR}/podman-auto-update.service
|
install ${SELINUXOPT} -m 644 contrib/systemd/auto-update/podman-auto-update.service ${DESTDIR}${SYSTEMDDIR}/podman-auto-update.service
|
||||||
install ${SELINUXOPT} -m 644 contrib/systemd/auto-update/podman-auto-update.timer ${DESTDIR}${SYSTEMDDIR}/podman-auto-update.timer
|
install ${SELINUXOPT} -m 644 contrib/systemd/auto-update/podman-auto-update.timer ${DESTDIR}${SYSTEMDDIR}/podman-auto-update.timer
|
||||||
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman.socket ${DESTDIR}${SYSTEMDDIR}/podman.socket
|
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman.socket ${DESTDIR}${SYSTEMDDIR}/podman.socket
|
||||||
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman.service ${DESTDIR}${SYSTEMDDIR}/podman.service
|
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman.service ${DESTDIR}${SYSTEMDDIR}/podman.service
|
||||||
|
install ${SELINUXOPT} -m 644 contrib/systemd/system/podman-restart.service ${DESTDIR}${SYSTEMDDIR}/podman-restart.service
|
||||||
else
|
else
|
||||||
install.systemd:
|
install.systemd:
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -531,10 +531,12 @@ export GOPATH=%{buildroot}/%{gopath}:$(pwd)/vendor:%{gopath}
|
||||||
%{_unitdir}/podman-auto-update.timer
|
%{_unitdir}/podman-auto-update.timer
|
||||||
%{_unitdir}/podman.service
|
%{_unitdir}/podman.service
|
||||||
%{_unitdir}/podman.socket
|
%{_unitdir}/podman.socket
|
||||||
|
%{_unitdir}/podman-restart.service
|
||||||
%{_usr}/lib/systemd/user/podman.service
|
%{_usr}/lib/systemd/user/podman.service
|
||||||
%{_usr}/lib/systemd/user/podman.socket
|
%{_usr}/lib/systemd/user/podman.socket
|
||||||
%{_usr}/lib/systemd/user/podman-auto-update.service
|
%{_usr}/lib/systemd/user/podman-auto-update.service
|
||||||
%{_usr}/lib/systemd/user/podman-auto-update.timer
|
%{_usr}/lib/systemd/user/podman-auto-update.timer
|
||||||
|
%{_usr}/lib/systemd/user/podman-restart.service
|
||||||
%{_usr}/lib/tmpfiles.d/podman.conf
|
%{_usr}/lib/tmpfiles.d/podman.conf
|
||||||
|
|
||||||
%if 0%{?with_devel}
|
%if 0%{?with_devel}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Podman Start All Containers With Restart Policy Set To Always
|
||||||
|
Documentation=man:podman-start(1)
|
||||||
|
StartLimitIntervalSec=0
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
Environment=LOGGING="--log-level=info"
|
||||||
|
ExecStart=/usr/bin/podman $LOGGING start --all --filter restart-policy=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -10,3 +10,6 @@ Type=exec
|
||||||
KillMode=process
|
KillMode=process
|
||||||
Environment=LOGGING="--log-level=info"
|
Environment=LOGGING="--log-level=info"
|
||||||
ExecStart=/usr/bin/podman $LOGGING system service
|
ExecStart=/usr/bin/podman $LOGGING system service
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -696,7 +696,9 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
||||||
reports := []*entities.ContainerStartReport{}
|
reports := []*entities.ContainerStartReport{}
|
||||||
var exitCode = define.ExecErrorCodeGeneric
|
var exitCode = define.ExecErrorCodeGeneric
|
||||||
containersNamesOrIds := namesOrIds
|
containersNamesOrIds := namesOrIds
|
||||||
|
all := options.All
|
||||||
if len(options.Filters) > 0 {
|
if len(options.Filters) > 0 {
|
||||||
|
all = false
|
||||||
filterFuncs := make([]libpod.ContainerFilter, 0, len(options.Filters))
|
filterFuncs := make([]libpod.ContainerFilter, 0, len(options.Filters))
|
||||||
if len(options.Filters) > 0 {
|
if len(options.Filters) > 0 {
|
||||||
for k, v := range options.Filters {
|
for k, v := range options.Filters {
|
||||||
|
@ -713,6 +715,10 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
||||||
}
|
}
|
||||||
containersNamesOrIds = []string{}
|
containersNamesOrIds = []string{}
|
||||||
for _, candidate := range candidates {
|
for _, candidate := range candidates {
|
||||||
|
if options.All {
|
||||||
|
containersNamesOrIds = append(containersNamesOrIds, candidate.ID())
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, nameOrID := range namesOrIds {
|
for _, nameOrID := range namesOrIds {
|
||||||
if nameOrID == candidate.ID() || nameOrID == candidate.Name() {
|
if nameOrID == candidate.ID() || nameOrID == candidate.Name() {
|
||||||
containersNamesOrIds = append(containersNamesOrIds, nameOrID)
|
containersNamesOrIds = append(containersNamesOrIds, nameOrID)
|
||||||
|
@ -720,8 +726,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ctrs, rawInputs, err := getContainersAndInputByContext(all, options.Latest, containersNamesOrIds, ic.Libpod)
|
||||||
ctrs, rawInputs, err := getContainersAndInputByContext(options.All, options.Latest, containersNamesOrIds, ic.Libpod)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,7 +508,9 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
||||||
reports := []*entities.ContainerStartReport{}
|
reports := []*entities.ContainerStartReport{}
|
||||||
var exitCode = define.ExecErrorCodeGeneric
|
var exitCode = define.ExecErrorCodeGeneric
|
||||||
containersNamesOrIds := namesOrIds
|
containersNamesOrIds := namesOrIds
|
||||||
|
all := options.All
|
||||||
if len(options.Filters) > 0 {
|
if len(options.Filters) > 0 {
|
||||||
|
all = false
|
||||||
containersNamesOrIds = []string{}
|
containersNamesOrIds = []string{}
|
||||||
opts := new(containers.ListOptions).WithFilters(options.Filters).WithAll(true)
|
opts := new(containers.ListOptions).WithFilters(options.Filters).WithAll(true)
|
||||||
candidates, listErr := containers.List(ic.ClientCtx, opts)
|
candidates, listErr := containers.List(ic.ClientCtx, opts)
|
||||||
|
@ -516,6 +518,10 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
||||||
return nil, listErr
|
return nil, listErr
|
||||||
}
|
}
|
||||||
for _, candidate := range candidates {
|
for _, candidate := range candidates {
|
||||||
|
if options.All {
|
||||||
|
containersNamesOrIds = append(containersNamesOrIds, candidate.ID)
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, nameOrID := range namesOrIds {
|
for _, nameOrID := range namesOrIds {
|
||||||
if nameOrID == candidate.ID {
|
if nameOrID == candidate.ID {
|
||||||
containersNamesOrIds = append(containersNamesOrIds, nameOrID)
|
containersNamesOrIds = append(containersNamesOrIds, nameOrID)
|
||||||
|
@ -530,7 +536,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctrs, err := getContainersByContext(ic.ClientCtx, options.All, false, containersNamesOrIds)
|
ctrs, err := getContainersByContext(ic.ClientCtx, all, false, containersNamesOrIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,4 +59,15 @@ load helpers
|
||||||
is "$output" "Error: fakepolicy invalid restart policy"
|
is "$output" "Error: fakepolicy invalid restart policy"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "podman start --all --filter" {
|
||||||
|
run_podman run -d $IMAGE /bin/true
|
||||||
|
cid_exited_0="$output"
|
||||||
|
run_podman run -d $IMAGE /bin/false
|
||||||
|
cid_exited_1="$output"
|
||||||
|
|
||||||
|
run_podman wait $cid_exited_0 $cid_exited_1
|
||||||
|
run_podman start --all --filter exited=0
|
||||||
|
is "$output" "$cid_exited_0"
|
||||||
|
}
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
|
Loading…
Reference in New Issue