diff --git a/docker/README.md b/docker/README.md
index 7465bd10f..6e2c51eee 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -86,7 +86,7 @@ This container have some options available via environment variables, these opti
Bind linked docker container to localhost socket using socat.
Any exported port from a linked container will be binded to the matching port on localhost.
- Disclaimer:
- As this option rely on the environment variable created by docker when a container is linked, this option should be deactivated in managed environment such as Rancher or Kubernetes (set to `0` or `false`)
+ As this option rely on the environment variable created by docker when a container is linked, this option should not be activated in managed environment such as Rancher or Kubernetes.
- **RUN_CROND**:
- Possible value:
`true`, `false`, `1`, `0`
diff --git a/docker/start.sh b/docker/start.sh
index a54c2a9bf..380a08263 100755
--- a/docker/start.sh
+++ b/docker/start.sh
@@ -1,8 +1,31 @@
#!/bin/sh
+## Container configuration
+SOCAT_LINK=${SOCAT_LINK:-false}
+RUN_CROND=${RUN_CROND:-false}
+
+## Container utils
+cleanup() {
+ # Cleanup SOCAT services and s6 event folder
+ # On start and on shutdown in case container has been killed
+ rm -rf $(find /app/gogs/docker/s6/ -name 'event')
+ rm -rf /app/gogs/docker/s6/SOCAT_*
+}
+
+create_volume_subfolder() {
+ # Create VOLUME subfolder
+ for f in /data/gogs/data /data/gogs/conf /data/gogs/log /data/git /data/ssh; do
+ if ! test -d $f; then
+ mkdir -p $f
+ fi
+ done
+}
+
+## Container option activators
create_socat_links() {
# Bind linked docker container to localhost socket using socat
USED_PORT="3000:22"
+ echo "init:socat | Socat links will be created (requested via SOCAT_LINK)" 1>&2
while read NAME ADDR PORT; do
if test -z "$NAME$ADDR$PORT"; then
continue
@@ -22,42 +45,37 @@ create_socat_links() {
EOT
}
-cleanup() {
- # Cleanup SOCAT services and s6 event folder
- # On start and on shutdown in case container has been killed
- rm -rf $(find /app/gogs/docker/s6/ -name 'event')
- rm -rf /app/gogs/docker/s6/SOCAT_*
+activate_crond () {
+ # Request s6 to run crond
+ echo "init:crond | Cron Daemon (crond) will be run as requested by s6" 1>&2
+ rm -f /app/gogs/docker/s6/crond/down
}
-create_volume_subfolder() {
- # Create VOLUME subfolder
- for f in /data/gogs/data /data/gogs/conf /data/gogs/log /data/git /data/ssh; do
- if ! test -d $f; then
- mkdir -p $f
- fi
- done
+deactivate_crond () {
+ # Tell s6 not to run the crond service
+ touch /app/gogs/docker/s6/crond/down
+}
+
+## Environment variable parser
+parse_container_options () {
+ # Parse opt-in / opt-out container optionss based on environment variable
+ # SOCAT_LINK: bind linked containers to localhost via socat
+ case $(echo "$SOCAT_LINK" | tr '[:upper:]' '[:lower:]') in
+ true|1) create_socat_links;;
+ esac
+ # RUN_CROND: request crond to be run inside the container
+ case $(echo "$RUN_CROND" | tr '[:upper:]' '[:lower:]') in
+ true|1) activate_crond;;
+ *) deactivate_crond;;
+ esac
}
+## Main
cleanup
create_volume_subfolder
+parse_container_options
-LINK=$(echo "$SOCAT_LINK" | tr '[:upper:]' '[:lower:]')
-if [ "$LINK" = "false" -o "$LINK" = "0" ]; then
- echo "init:socat | Will not try to create socat links as requested" 1>&2
-else
- create_socat_links
-fi
-
-CROND=$(echo "$RUN_CROND" | tr '[:upper:]' '[:lower:]')
-if [ "$CROND" = "true" -o "$CROND" = "1" ]; then
- echo "init:crond | Cron Daemon (crond) will be run as requested by s6" 1>&2
- rm -f /app/gogs/docker/s6/crond/down
-else
- # Tell s6 not to run the crond service
- touch /app/gogs/docker/s6/crond/down
-fi
-
-# Exec CMD or S6 by default if nothing present
+## End of initialization: exec CMD or s6 by default
if [ $# -gt 0 ];then
exec "$@"
else