I was trying to follow the tutorial here using upStart (Run php script as daemon process), but I ran into some snags when I get the error 'startserver: unrecognized service'
Here is some images to show what I tried
At the bottom of the console is where the errors are. I also show proof that my file is in /etc/init where it should be in the docker container. I logged in using docker exec -it draftandpermit_web_1 bash
Am I missing something?
Other Reference Data:
startserver.conf
# Info
description "Start Server"
author "Joseph Astrahan"
# Events
start on startup
stop on shutdown
# Automatically respawn
respawn
respawn limit 20 5
# Run the script!
# Note, in this example, if your PHP script returns
# the string "ERROR", the daemon will stop itself.
script
[ $(exec /usr/bin/php -f /var/www/callcenter/livesite/bin/startwebsocketserver.php) = 'ERROR' ] && ( stop; exit 1; )
end script
I activate it either manually as you saw in the images or using my convenience script
echo "Copying startserver.conf to /etc/init"
docker exec -it draftandpermit_web_1 bash -c "cd /app/docker; cp -f startserver.conf /etc/init/"
echo "Stopping & Starting the WebSocket & HTTP Server"
docker exec -it draftandpermit_web_1 bash -c "service startserver stop"
docker exec -it draftandpermit_web_1 bash -c "service startserver start"
Keep in mind paths are correct for where the file is since I manually went into the container to look at /etc/init as shown in the images.
Docker is neither an init system nor does it run traditional init systems without some hacks. The first process you run in the Docker container will be PID 1. This could be a supervisor (like supervisord, s6, dumb-init).
However, more generally, you can just run the process you want and handle running in the foreground or background with options to the docker run
command. In this example your Docker command (or CMD
in the Dockerfile
) can just be php -f /var/www/callcenter/livesite/bin/startwebsocketserver.php
. Then, run your container with the -d
option and it will run in the background. You can attach to it with docker attach
or just watch the output with docker logs
.
If you actually need to use some sort of process supervisor (such as, when you need to have multiple processes running in the container), then I'd start looking to Docker init options out there. I mentioned a couple and there are more. Upstart won't work inside a container.