0

I am trying to operate DeepDetect (a machine learning server) in Docker [note this is not a DeepDetect question - it is simply a Bash question]. However, I am running into a more general Linux/bash problem that I am hoping to get help on.

Here is what I need to do:

  1. From a shell script launched via Dockerfile ENTRYPOINT, Start DeepDetect server, block on it (it is a server so it should run forever). I want the script running this to be the root process, so that if it ever crashes, Docker will restart the container.

  2. After the server is running, from the same script, send a curl as follows to the above now-running server:

curl -X PUT "http://localhost/services/age " -d '{ "mllib":"caffe", "description":"age classification", "type":"supervised", "parameters":{ "input":{ "connector":"image", "height":227, "width":227 }, "mllib":{ "nclasses":8 } }, "model":{ "repository":"/models/age_model" } }'

OK so here is my problem - how can I run the curl if the server is running forever? It seems like I need to somehow kickoff another process in the background before the server starts, that then comes back after the server starts and runs the above curl expression.

Does anyone have any idea how to accomplish this "call script in 30 seconds" issue? Any help is greatly appreciated!

2 Answers 2

2

For the basic question:

#!/usr/bin/env bash
./start-server.sh &
sleep 30
curl […]
wait

Now inevitably there will be problems with sleep 30 - sometimes the server might take longer to start up, or it might be in the process of restarting exactly when curl runs. You can add lots of complexity to retry or to check whether the server is available (typically with a different curl) before doing what you want.

1
  • 1
    Thanks! If I do this, though - won't the Docker stop? Because the start-server will run in the background, then curl will finish, then this shell script will terminate causing the Docker to stop. Would the fix to be to add some sort of "wait for process" command that waits for the start-server?
    – A X
    Aug 27, 2018 at 5:54
1

DeepDetect server should be daemonized in container (run as pid 1):

CMD ["deepdetect"]

In entrypoint script you can wait for server using simple while loop:

while ! $(curl --output /dev/null --silent --head --fail 
http://localhost:80); do
    >&2 echo "Server is unavailable - sleeping"
    sleep 1
done

I didn't check this, but you can try this idea anyway. Also you should use exec format for entrypoint and cmd (not shell):

ENTRYPOINT ["/entrypoint.sh"]

You must log in to answer this question.

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