From 2a32f59c055f76b3420726930a08a0a95474cc2c Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 22 Feb 2018 03:47:37 +0100 Subject: Simplify and add uid to /etc/passwd on startup to keep getpwuid() happy --- adei/Dockerfile | 8 +++++--- adei/docker-entrypoint.sh | 6 ++++++ adei/scripts/run-apache.sh | 31 +++++++++++++++++++------------ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/adei/Dockerfile b/adei/Dockerfile index 8ecaa2e..3556644 100644 --- a/adei/Dockerfile +++ b/adei/Dockerfile @@ -25,7 +25,6 @@ VOLUME /adei/src VOLUME /adei/cfg VOLUME /adei/tmp VOLUME /adei/sys -VOLUME /adei/ovr COPY supervisor/supervisord.conf /etc/supervisord.conf @@ -43,11 +42,14 @@ RUN rm -rf /srv/www/htdocs/adei && \ RUN ln -sf /etc/mime.types /etc/apache2/mime.types && \ find /etc/apache2 -type d -exec chmod +rx '{}' \; && \ chmod -R +r /etc/apache2 && \ - mv /etc/apache2 /opt/ && \ - ln -s /adei/ovr/apache2 /etc/apache2 && \ + chmod a+w /etc/apache2/listen.conf && \ + chmod a+w /etc/apache2/server-tuning.conf && \ sed -i'' -re 's@/var/run@/tmp@' /usr/sbin/start_apache2 && \ chmod +x /usr/sbin/start_apache2 +# Ugly python needs to resolve user name +RUN chmod g=u /etc/passwd + ENV MYSQL_SERVER adei-mysql ENV MYSQL_PORT 3306 ENV MYSQL_USER adei diff --git a/adei/docker-entrypoint.sh b/adei/docker-entrypoint.sh index a82a970..f4d9f20 100755 --- a/adei/docker-entrypoint.sh +++ b/adei/docker-entrypoint.sh @@ -2,5 +2,11 @@ set -e +if ! whoami &> /dev/null; then + if [ -w /etc/passwd ]; then + echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd + fi +fi + echo "Running: $@" exec "$@" diff --git a/adei/scripts/run-apache.sh b/adei/scripts/run-apache.sh index e7d894b..159a265 100755 --- a/adei/scripts/run-apache.sh +++ b/adei/scripts/run-apache.sh @@ -1,13 +1,6 @@ #! /bin/bash LOCK_FILE=.lock -( - flock -x 10 - if [ ! -d /adei/ovr/apache2 ]; then - cp -ar /opt/apache2 /adei/ovr/ - fi -) 10> /adei/ovr/$LOCK_FILE - ( flock -x 10 if [ ! -f /adei/cfg/apache.conf ]; then @@ -15,8 +8,22 @@ LOCK_FILE=.lock fi ) 10> /adei/cfg/$LOCK_FILE + +function ised { +#Creates temporary file in the file folder +# sed -i'' "$@" + + tmp=$(mktemp) + fn="${@: -1}" + echo $fn + sed "$@" > "$tmp" + cat "$tmp" > "$fn" + + rm -f "$tmp" +} + #Keep 80 & 443 -#sed -i'' -re '/Listen/ { /(80|443)/!d }' /etc/apache2/listen.conf +#ised -re '/Listen/ { /(80|443)/!d }' /etc/apache2/listen.conf #if [ -n "$ADEI_PORTS" ]; then # for port in $ADEI_PORTS; do # [ $port -eq 80 ] && continue @@ -49,10 +56,10 @@ if [ -n "$APACHE_SERVERS" -a "$APACHE_SERVERS" -ne 0 ]; then min_spare=0 max_spare=0 fi - [ $start -eq 0 ] || sed -i'' -re "s/StartServers(.*)/StartServers $start/" /etc/apache2/server-tuning.conf - [ $limit -eq 0 ] || sed -i'' -re "s/MaxClients(.*)/MaxClients $limit/" /etc/apache2/server-tuning.conf - [ $min_spare -eq 0 ] || sed -i'' -re "s/MinSpareServers(.*)/MinSpareServers $min_spare/" /etc/apache2/server-tuning.conf - [ $max_spare -eq 0 ] || sed -i'' -re "s/MaxSpareServers(.*)/MaxSpareServers $max_spare/" /etc/apache2/server-tuning.conf + [ $start -eq 0 ] || ised -re "s/StartServers(.*)/StartServers $start/" /etc/apache2/server-tuning.conf + [ $limit -eq 0 ] || isedt -re "s/MaxClients(.*)/MaxClients $limit/" /etc/apache2/server-tuning.conf + [ $min_spare -eq 0 ] || ised -re "s/MinSpareServers(.*)/MinSpareServers $min_spare/" /etc/apache2/server-tuning.conf + [ $max_spare -eq 0 ] || ised -re "s/MaxSpareServers(.*)/MaxSpareServers $max_spare/" /etc/apache2/server-tuning.conf fi rm -f /tmp/httpd.pid -- cgit v1.2.1