From deff39cd5f70b0f42e7358c4f7a91cc1e7d767d8 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 13 Aug 2014 00:34:00 +0200 Subject: [PATCH] Prepare various background tasks. --- Dockerfile | 22 +++++++++++++++++++--- Makefile | 3 +++ configs/supervisor-cron.conf | 2 ++ configs/supervisor-ssh.conf | 2 ++ configs/supervisord.conf | 2 ++ scripts/start.sh | 13 ++++++++++--- 6 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 configs/supervisor-cron.conf create mode 100644 configs/supervisor-ssh.conf create mode 100644 configs/supervisord.conf diff --git a/Dockerfile b/Dockerfile index 15c5ef9..aa0c003 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,14 +3,30 @@ MAINTAINER Glenn Y. Rolland ENV DEBIAN_FRONTEND noninteractive RUN apt-get update -RUN apt-get install -q -y supervisor -RUN apt-get install -q -y reprepro + + +# Install supervisor for managing services +RUN apt-get install -q -y supervisor cron openssh-server pwgen reprepro screen vim-tiny + +RUN service supervisor stop +ADD configs/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + + +# Install cron for managing regular tasks +ADD configs/supervisor-cron.conf /etc/supervisor/conf.d/cron.conf +RUN sed -i 's/\(session *required *pam_loginuid.so\)/#\1/' /etc/pam.d/cron + + +# Install ssh +ADD configs/supervisor-ssh.conf /etc/supervisor/conf.d/ssh.conf +RUN mkdir /var/run/sshd ENV DEBIAN_FRONTEND newt -VOLUME /data ADD scripts/start.sh /start.sh +RUN chmod 755 /start.sh +VOLUME /data EXPOSE 80 EXPOSE 22 CMD ["/bin/bash", "/start.sh"] diff --git a/Makefile b/Makefile index 0165b0c..0fe2d0d 100644 --- a/Makefile +++ b/Makefile @@ -2,3 +2,6 @@ build: docker build -t glenux/debian-repo . +run: + docker run -i -t glenux/debian-repo /bin/bash + diff --git a/configs/supervisor-cron.conf b/configs/supervisor-cron.conf new file mode 100644 index 0000000..c072909 --- /dev/null +++ b/configs/supervisor-cron.conf @@ -0,0 +1,2 @@ +[program:cron] +command=/usr/sbin/cron -f diff --git a/configs/supervisor-ssh.conf b/configs/supervisor-ssh.conf new file mode 100644 index 0000000..a1c6f2f --- /dev/null +++ b/configs/supervisor-ssh.conf @@ -0,0 +1,2 @@ +[program:ssh] +command=/usr/sbin/sshd -D diff --git a/configs/supervisord.conf b/configs/supervisord.conf new file mode 100644 index 0000000..54296b8 --- /dev/null +++ b/configs/supervisord.conf @@ -0,0 +1,2 @@ +[supervisord] +nodaemon=true diff --git a/scripts/start.sh b/scripts/start.sh index b42681a..31ff963 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -3,13 +3,20 @@ # Many thanks to John Fink for the # inspiration and to his great work on docker-wordpress' -# let's create a user to ssh into +# let's create a user to SSH into SSH_USERPASS=`pwgen -c -n -1 8` mkdir /home/user useradd -G sudo -d /home/user user chown user /home/user -echo user:$SSH_USERPASS | chpasswd -echo ssh user password: $SSH_USERPASS +echo "user:$SSH_USERPASS" | chpasswd +echo "ssh user password: $SSH_USERPASS" + +CRONFILE=`mktemp` +cat > $CRONFILE <> /home/user/pif.log +EOF +crontab -u user $CRONFILE +rm -f $CRONFILE supervisord -n