From 9f73eb1af54ae42e74135f4d052ba1f93167585b Mon Sep 17 00:00:00 2001 From: Hugh Ratsch Date: Thu, 20 Feb 2025 15:48:09 -0600 Subject: [PATCH] updated notes --- src/rhcsa.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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