Created
December 22, 2025 20:07
-
-
Save seia-soto/f38965b3977e32110c5a7b147a16d30e to your computer and use it in GitHub Desktop.
Podman compose init rc-script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/sbin/openrc-run | |
| command_user="<CHANGE_ME_TO_USER>" | |
| name="zz<CHANGE_ME_TO_PROJECT_NAME>" | |
| output_log="/var/log/${name}.log" | |
| error_log="/var/log/${name}.err" | |
| # PID file required by start-stop-daemon for tracking, must be in a root-owned directory | |
| PIDFILE="/run/${name}.pid" | |
| WORKING_DIR="<CHANGE_ME_TO_WORKING_DIR>" | |
| COMMAND="/usr/bin/podman-compose" | |
| COMMAND_ARGS="up --remove-orphans" | |
| STOP_COMMAND_ARGS="down" | |
| depend() { | |
| need localmount net cgroups | |
| } | |
| start_pre() { | |
| if [ ! -d "${WORKING_DIR}" ]; then | |
| eerror "WORKING_DIR=${WORKING_DIR} not found for user ${command_user}. Is directory available?" | |
| return 1 | |
| fi | |
| cd "${WORKING_DIR}" | |
| if [ -f "${PIDFILE}" ]; then | |
| elog "Found an ungratefully exited PID file! Trying to clean-up running process." | |
| su -c "${COMMAND} ${STOP_COMMAND_ARGS}" - "${command_user}" | |
| fi | |
| # Ensure log files exist and have correct permissions | |
| checkpath -f --mode 0640 --owner "${command_user}:${command_user}" "${output_log}" "${error_log}" | |
| } | |
| stop_pre() { | |
| cd "${WORKING_DIR}" | |
| } | |
| start() { | |
| ebegin "Starting ${name} in ${WORKING_DIR}" | |
| start-stop-daemon --start --quiet --background --make-pidfile --pidfile "${PIDFILE}" \ | |
| --chuid "${command_user}" --chdir "${WORKING_DIR}" \ | |
| --stdout "${output_log}" --stderr "${error_log}" \ | |
| --exec "${COMMAND}" -- ${COMMAND_ARGS} | |
| eend $? | |
| } | |
| stop() { | |
| ebegin "Stopping ${name}" | |
| start-stop-daemon --stop --quiet --pidfile "${PIDFILE}" \ | |
| --chuid "${command_user}" --chdir "${WORKING_DIR}" \ | |
| --signal INT | |
| if [ -f "${PIDFILE}" ]; then | |
| # Clean up the PID file after stop | |
| rm "${PIDFILE}" | |
| fi | |
| eend $? | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment