4

I'm using s6 (http://skarnet.org/software/s6/) in order to supervise multiple processes.

I have couple services in my /etc/s6/ folder and one of them just need to call the start action from an init.d script.

As of now the script is well started but then it's trying to re-start it again and again.

Is there a way to avoid this ?

2
  • If you're going to copy and paste the same question you've already posted elsewhere, at least have the decency to remove the vote count from the other site so we don't feel like an afterthought.
    – user143703
    May 28, 2015 at 18:03
  • ... thank you for your helpful comment (thumbup) and I did that as I opened the question in the wrong platform ... And I have no idea about your vote things and to be honest ... I don't care about the votes ! Next one ?
    – ZedTuX
    May 28, 2015 at 20:19

3 Answers 3

6

If your service is a one-shot, i.e. it needs to run once and die, but not be kept alive, then it's not a good candidate for supervision. Process supervision is only good for long-running processes, a.k.a. daemons.

The correct solution to your problem is to take your one-shot script out of the set of supervised services, and run it at some point in your initialization procedure without trying to have s6-svscan/s6-supervise manage it.

2
  • 1
    Hey you're one of the s6 developers ! :-) Salut !
    – ZedTuX
    May 29, 2015 at 13:21
  • I think, he's not only one of the developers, but developer behind Skarnet and s6.
    – xZero
    Nov 23, 2018 at 14:16
5

You can do this with s6, by including s6-svc -O /etc/s6/servicefolder at the beginning of your run script. This will tell to s6 to not start this service again.

Source: https://skarnet.org/software/s6/s6-svc.html

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .