EricssonResearch / calvin-base

Calvin is an application environment that lets things talk to things, among other things.
Apache License 2.0
282 stars 91 forks source link

dcswebBG.sh: Web server from cli without TTY #53

Closed imriss closed 8 years ago

olaan commented 8 years ago

I'd prefer to have it as an option to the dcsweb script rather than a separate script.. How about:

#!/bin/sh

# Defaults
PORT="8000"
IMAGE="erctcalvin/calvin:master"
FLAGS="-it" # Run interactive w/ tty

usage() {
    echo "Usage: $(basename $0) \n\
    -i <image>[:<tag>]   : Docker image (and tag) to use [$IMAGE]\n\
    -p <port>            : Port to use [$PORT]\n\
    -d                   : Detach and run in background\n"
    exit 1
}

while getopts "i:p:hd" opt; do
    case $opt in
        p)
            PORT="$OPTARG"
            ;;
        i)
            IMAGE=$OPTARG
            ;;
        d)
            FLAGS=-d
            ;;
        h)
            usage;
            ;;
    esac
done

docker run -p $PORT:8000 $FLAGS --entrypoint csweb $IMAGE
imriss commented 8 years ago

Good idea. Maybe you can also have another option for background without detached (to have the log):

#!/bin/sh

# Defaults
PORT="8000"
IMAGE="erctcalvin/calvin:master"
FLAGS="-it" # Run interactive w/ tty

usage() {
    echo "Usage: $(basename $0) \n\
    -i <image>[:<tag>]   : Docker image (and tag) to use [$IMAGE]\n\
    -p <port>            : Port to use [$PORT]\n\
    -d                   : Detach and run in background\n
    -b                   : Run in background (Attached. To be used along with \&)\n"
    exit 1
}

while getopts "i:p:hdb" opt; do
    case $opt in
        p)
            PORT="$OPTARG"
            ;;
        i)
            IMAGE=$OPTARG
            ;;
        d)
            FLAGS=-d
            ;;
        b)
            FLAGS=
            ;;
        h)
            usage;
            ;;
    esac
done

docker run -p $PORT:8000 $FLAGS --entrypoint csweb $IMAGE
olaan commented 8 years ago

What do you gain from that?

To get the log from the container, one can use the returned container id, e.g.

$ docker logs -f $(./dcsweb.sh -d)

Is that insufficient?

imriss commented 8 years ago

Thanks. That would work fine.

olaan commented 8 years ago

Available on develop branch, commit b28515ee3355eb562310f43be393d0dc4b285156.

Closing.