Reputation: 91630
I'm working on a Docker container built on Phusion's baseimage which needs to have a number of services only started on demand. I'd like these services to remain as runit
services, I'd just like them to not automatically start on boot.
As seen in their documentation, you can easily add a service by creating a folder in /etc/service
with the name of your service, ie: /etc/service/jboss
. Next, you must create and chmod +x
a file in that service directory called run
which will execute the startup of your service.
How can I do this and ensure that the service will not start on boot? The goal is still to be able to do sv start jboss
, but to not have it start on boot.
Upvotes: 3
Views: 4735
Reputation: 1124
With phusion/baseimage:0.9.17
(not sure in which version it was introduced) you can bake RUN touch /etc/service/jboss/down
in your Dockerfile. It prevents the runit from starting it on boot and you're still able to sv start jboss
later.
Upvotes: 3
Reputation: 165
Add your services to /etc/sv/<SERVICE_NAME>/
and add the run
executable just like you are doing now. When you are ready to run the service, simply symlink it to /etc/service
and runit will pick it up and start running it automatically.
Here's a short (non-optimized) Dockerfile that shows a disabled service and an enabled service. The enabled service will start at Docker run. The disabled service will not start until it is symlinked to /etc/service
, at which time runit will start it within five seconds.
FROM phusion/baseimage
RUN mkdir /etc/sv/disabled_service
ADD disabled_service.sh /etc/sv/disabled_service/run
RUN chmod 700 /etc/sv/disabled_service/run
RUN mkdir /etc/sv/enabled_service
ADD enabled_service.sh /etc/sv/enabled_service/run
RUN chmod 700 /etc/sv/enabled_service/run
RUN ln -s /etc/sv/enabled_service /etc/service/enabled_service
CMD ["/sbin/my_init"]
Upvotes: 4
Reputation: 3
I'm looking at exactly the same problem (when running Cassandra in a container) and I haven't found a clean answer. Here are the two hacky ways I've come up with.
-Have an early runlevel script that moves a file in and out of run
depending on whether you want something to start at boot.
-(mis)Use one of the service
control commands for runit
to actually start your service and use a dummy run
command to bypass the automatic start.
Both methods are clearly less than ideal, but they've worked for some purposes.
Upvotes: 0