diff --git a/src/rhcsa.md b/src/rhcsa.md index 9a0fae6..1374f89 100644 --- a/src/rhcsa.md +++ b/src/rhcsa.md @@ -998,4 +998,34 @@ podman volume ls ### run the container with the volume podman run --name mywebserver -d -p 8080:80 -v myvolume:/var/www/html:Z nginx +``` + +### Scheduling Containerised Services with Systemd +> Note: You can use systemd to schedule containerised services. +>> configure the service to run under a user's account even when the user is not logged into the system +```bash +### enable linger for the user +sudo loginctl enable-linger user1 + +### create a systemd service +mkdir -p /home/user1/.config/systemd/user +podman pull nginx + +### run the container +podman run -d --name mynginx -p 8080:80 nginx + +### cd into the user's home directory +cd /home/user1/.config/systemd/user +podman generate systemd --name mynginx --files --new # generate the systemd service file + +### ensure the service file is wantedby default.target +[Install] +WantedBy=default.target + +systemctl --user daemon-reload # reload the systemd user daemon +systemctl --user enable container-mynginx.service # enable the mynginx service + +systemctl --user status container-mynginx.service # check the status of the mynginx service + +### after rebooting the system, the service will start automatically ``` \ No newline at end of file