Improved image and documentation
authorkaliko <kaliko@azylum.org>
Sun, 25 Oct 2015 16:57:07 +0000 (17:57 +0100)
committerkaliko <kaliko@azylum.org>
Sun, 25 Oct 2015 16:57:07 +0000 (17:57 +0100)
README [deleted file]
README.rst [new file with mode: 0644]
do
sima/Dockerfile
sima/mpd-sima [moved from sima/sima with 100% similarity]
sima/mpd.conf
sima/start

diff --git a/README b/README
deleted file mode 100644 (file)
index 1ff01de..0000000
--- a/README
+++ /dev/null
@@ -1,23 +0,0 @@
-Description
-===========
-
-This images contains MPD, icecast2 and MPD_sima in order to serve an audio stream over http.
-
-Configuration
-=============
-
-Running a container to play to content of your music library:
-
-  - Audio stream available from http://127.0.0.1:8001
-  - MPD available on 127.0.0.1:6601
-
-..code-block:: sh
-        LISTEN=127.0.0.1
-        MUSIC="/path/to/my/music/library"
-        OPTIONS="-p ${LISTEN}:8001:8000"
-        OPTIONS="${OPTIONS} -p ${LISTEN}:6601:6600"
-        OPTIONS="${OPTIONS} --volume ${MUSIC}:/var/lib/mpd/music:ro"
-        docker run ${OPTIONS} --detach=true --name sima kaliko/sima
-
-
- vim: syntax=rst ft=rst
diff --git a/README.rst b/README.rst
new file mode 100644 (file)
index 0000000..33bab51
--- /dev/null
@@ -0,0 +1,49 @@
+Description
+===========
+
+This image contains MPD, icecast2 and MPD_sima in order to serve an audio stream over http.
+
+MPD is looking for music in /music (music_directory option) and keeps its
+dataset in /var/lib/mpd (options: playlist_directory, {db,sticker,state}_file).
+
+Configuration
+=============
+
+Running a container to play to content of your music library:
+
+  - Audio stream available from http://127.0.0.1:8001
+  - MPD available on 127.0.0.1:6601
+  - Music directory: /path/to/my/music/library
+
+..code-block:: sh
+    LISTEN=127.0.0.1
+    MUSIC="/path/to/my/music/library"
+    OPTIONS="-p ${LISTEN}:8001:8000"
+    OPTIONS="${OPTIONS} -p ${LISTEN}:6601:6600"
+    OPTIONS="${OPTIONS} --volume ${MUSIC}:/music:ro"
+    docker run ${OPTIONS} --detach=true --name sima kaliko/sima
+
+To run mpd-sima with a specific configuration mount the file in the running container.
+When /etc/mpd-sima.cfg is present in the container the default is to read it.
+
+..code-block:: sh
+    OPTIONS="-P --detach=true"
+    docker run -v ./my.config:/etc/mpd-sima.cfg ${OPTIONS} --name sima kaliko/sima
+    # Discover ports with "docker port sima"
+
+Mounting your music directory and saving MPD database in ${PWD}/data:
+
+..code-block:: sh
+    OPTIONS="-P --detach=true"
+    docker run -v ~/Music:/music:ro -v ${PWD}/data:/var/lib/mpd ${OPTIONS} --name sima kaliko/sima
+    # Discover ports with "docker port sima"
+
+Default option to run mpd-sima is "--log /var/log/mpd/mpd-sima.log".
+Environment variable MPD_SIMA might be used to override default command line options.
+
+..code-block:: sh
+    OPTIONS="-P --detach=true"
+    docker run --env="MPD_SIMA=--log-level debug --log /var/log/mpd/mpd-sima.log" -v ${PWD}/log:/var/log/mpd ${OPTIONS} --name sima kaliko/sima
+    # Discover ports with "docker port sima"
+
+ vim: syntax=rst ft=rst
diff --git a/do b/do
index ce54532..867d8ae 100755 (executable)
--- a/do
+++ b/do
@@ -7,7 +7,7 @@ MPD_PORT=${MPDPORT:-6601}
 LISTEN=${LISTEN:-127.0.0.1}
 
 # make output verbose
-set -o xtrace -o nounset
+#set -o xtrace -o nounset
 
 _conf () {
     # Get the latest icecast conf
@@ -24,20 +24,41 @@ build () {
     docker build -t kaliko/sima ${DIR}/sima
 }
 
+log () {
+    if [ "$(docker inspect --format='{{.State.Running}}' sima)" = "true" ]; then
+        docker logs -f sima
+    fi
+}
+
+stop () {
+    docker stop -t 3 sima
+}
+
+inspect () {
+    docker port sima | awk '$1 ~ "6600/tcp" { printf "MPD running on: %s\n", $3 }'
+    docker port sima | awk '$1 ~ "8000/tcp" { printf "HTTP running on: http://%s\n", $3 }'
+}
+
 run () {
     # Start
-    test -z "${MUSIC}" && { echo "Need a music directory to mount please set MUSIC var"; exit 1; }
-    docker ps -a | grep 'sima'
-    if [ "$?" -ne 0 ]; then
-        echo 'launching a new sima container'
-        local options="-p ${LISTEN}:${ICE_PORT}:8000"
-        options="${options} -p ${LISTEN}:${MPD_PORT}:6600"
-        options="${options} --volume ${MUSIC}:/var/lib/mpd/music:ro"
-        docker run ${options} --detach=true --name sima kaliko/sima
-    else
-        echo 'running the current sima container'
-        docker start sima
-    fi
+    IS_RUNNING=$(docker inspect --format='{{.State.Running}}' sima)
+    case $IS_RUNNING in
+        true)
+            echo 'Already running container'
+            ;;
+        false)
+            echo 'running the current sima container'
+            docker start sima
+            ;;
+        else)
+            test -z "${MUSIC}" && { echo "Need a music directory to mount please set MUSIC var"; exit 1; }
+            echo 'launching a new sima container'
+            local options="-p ${LISTEN}:${ICE_PORT}:8000"
+            options="${options} -p ${LISTEN}:${MPD_PORT}:6600"
+            options="${options} --volume ${MUSIC}:/var/lib/mpd/music:ro"
+            docker run ${options} --detach=true --name sima kaliko/sima
+            ;;
+    esac
 }
 
 $@
index 34f773b..43ac097 100644 (file)
@@ -6,17 +6,18 @@ RUN apt-get -y update && apt-get -y upgrade && apt-get install -y --no-install-r
 RUN apt-get clean
 RUN usermod --shell /bin/dash icecast2
 RUN usermod --shell /bin/dash mpd
+RUN install -d -o mpd /run/mpd
 ADD mpd.conf /etc/mpd.conf
 
 RUN virtualenv -p python3 /var/lib/mpd-sima
-RUN bash -c "source /var/lib/mpd-sima/bin/activate && pip install MPD_sima"
+RUN bash -c "source /var/lib/mpd-sima/bin/activate && pip install MPD_sima==0.14.0"
 
-VOLUME /var/lib/mpd/music/
+VOLUME /var/lib/mpd/
 
 # expose icecast and mpd
 EXPOSE 8000 6600
 
 ADD start /usr/bin/start-sima
-ADD sima /usr/bin/sima
+ADD mpd-sima /usr/bin/mpd-sima
 
 ENTRYPOINT ["/bin/sh", "/usr/bin/start-sima"]
similarity index 100%
rename from sima/sima
rename to sima/mpd-sima
index d711069..3467684 100644 (file)
@@ -1,39 +1,41 @@
-music_directory                "/var/lib/mpd/music"\r
-playlist_directory     "/var/lib/mpd/playlists"\r
-db_file                                "/var/lib/mpd/tag_cache"\r
-log_file                       "/var/log/mpd/mpd.log"\r
-pid_file                       "/var/lib/mpd/pid"\r
-state_file                     "/var/lib/mpd/state"\r
-sticker_file           "/var/lib/mpd/sticker.sql"\r
-user                           "mpd"\r
-#group                         "nogroup"\r
-bind_to_address                "any"\r
-#bind_to_address       "/run/mpd/socket"\r
-#port                          "6600"\r
-#log_level                     "default"\r
-zeroconf_enabled       "no"\r
-#zeroconf_name         "Music Player"\r
-filesystem_charset     "UTF-8"\r
-id3v1_encoding         "UTF-8"\r
-\r
-# MPD_sima's icecast conf's\r
-audio_output {\r
-       enabled         "yes"\r
-       type            "shout"\r
-#      protocol        "icecast2"        # default to icecast2\r
-#      encoding        "vorbis"                # default is vorbis\r
-#      encoding        "flac"\r
-       name            "Sima Vorbis Stream"\r
-       host            "localhost"\r
-       port            "8000"\r
-       mount           "/sima.ogg"\r
-       format          "44100:16:2"\r
-       quality         "8.0"\r
-#      bitrate         "128"\r
-#      user            "source"                # default source\r
-       password        "hackme"\r
-       description     "MPD_sima's radio"   # optional\r
-#      genre           "jazz"            # optional\r
-#      public          "no"                    # optional\r
-#      timeout         "2"              # optional\r
-}\r
+music_directory                "/music"
+playlist_directory     "/var/lib/mpd/playlists"
+db_file                                "/var/lib/mpd/tag_cache"
+log_file                       "/var/log/mpd/mpd.log"
+pid_file                       "/run/mpd/mpd.pid"
+state_file                     "/var/lib/mpd/state"
+sticker_file           "/var/lib/mpd/sticker.sql"
+user                           "mpd"
+#group                         "nogroup"
+bind_to_address                "any"
+bind_to_address                "/run/mpd/socket"
+#port                          "6600"
+#log_level                     "default"
+zeroconf_enabled       "no"
+#zeroconf_name         "Music Player"
+filesystem_charset     "UTF-8"
+id3v1_encoding         "UTF-8"
+
+# MPD_sima's icecast conf's
+audio_output {
+       enabled         "yes"
+       type            "shout"
+#      protocol        "icecast2"              # default to icecast2
+#      encoding        "vorbis"                # default is vorbis
+#      encoding        "flac"
+       name            "Sima Vorbis Stream"
+       host            "localhost"
+       port            "8000"
+       mount           "/sima.ogg"
+       format          "44100:16:2"
+       quality         "8.0"
+#      bitrate         "128"
+#      user            "source"                # default source
+       password        "hackme"
+       description     "MPD_sima's radio"              # optional
+#      genre           "jazz"          # optional
+#      public          "no"            # optional
+#      timeout         "2"              # optional
+}
+
+# vim: ft=conf
index 09c268d..6211e9e 100644 (file)
@@ -5,12 +5,15 @@ su -c "icecast2 -b -c /etc/icecast2/icecast.xml" icecast2
 
 su -c "mpd /etc/mpd.conf" mpd
 
-if [ -e /etc/mpd-sima.cfg ]; then
-    OPTIONS="${OPTIONS} --config /etc/mpd-sima.cfg"
+OPTIONS=""
+if [ -z "${MPD_SIMA}" ];then
+    if [ -e /etc/mpd-sima.cfg ]; then
+        OPTIONS="--config /etc/mpd-sima.cfg"
+    fi
 fi
 
-OPTIONS="${OPTIONS} --log /var/log/mpd/mpd-sima.log --daemon"
-su -c "sh /usr/bin/sima ${OPTIONS}" mpd
+MPD_SIMA=${MPD_SIMA:-"--log /var/log/mpd/mpd-sima.log"}
+su -c "sh /usr/bin/mpd-sima --daemon ${OPTIONS} ${MPD_SIMA}" mpd
 
 tail -F /var/log/icecast2/access.log \
         /var/log/icecast2/error.log \