If s6 is running in a docker container and you can't control how it's started, then you can't use s6-svc -O /etc/s6/my_service
.
Assuming s6's services in the container are located at /etc/s6/
, you can do this instead:
docker-compose.yml
:
volumes:
- ./data:/data # a mapped or named volume
- ./run:/etc/s6/custom/run:ro
run
:
#!/bin/sh
# ensure not run (successfully) before
if [ -f /data/custom-init-performed ]; then
echo 'INFO: custom init already performed'
s6-svc -D /etc/s6/custom # prevent s6 from restarting service
exit 0
fi
# ensure container healthy
# if you're using healthchecks then use whatever url is applicable here
# if not, use another approach to determine whether container is ready
until [ $(curl -sf http://localhost:3000/api/healthz | grep -E '^ "status": "pass",$' | wc -l) = 1 ]; do
echo 'WARN: container not healthy yet, will retry...' >&2
sleep 5
done
# do once-only init work
# ...
# prevent script's core logic from running again
touch /data/custom-init-performed
# prevent s6 from restarting service
s6-svc -D /etc/s6/custom
exit 0