#!/sbin/openrc-run
supervisor=supervise-daemon

name="Podman API service"
description="Listening service that answers API calls for Podman"

command=/usr/bin/podman
command_args="system service ${podman_opts:=--time 0} $podman_uri"
command_user="${podman_user:=root}"

extra_commands="start_containers"
description_start_containers="Start containers with restart policy set to always"

depend() {
	need sysfs cgroups
}

start_containers() {
	ebegin "Starting containers with restart policy set to always"
	su "$podman_user" -s /bin/sh -c "$command start --all --filter restart-policy=always"
	eend $?
}

start_pre() {
	if [ "$podman_user" = "root" ]; then
		einfo "Configured as rootful service"
		checkpath -d -m 0755 /run/podman
	else
		einfo "Configured as rootless service"
		modprobe tun
		modprobe fuse
	fi
}

start_post() {
	start_containers
}
