initial commit

This commit is contained in:
Andy 2016-07-16 18:09:54 +02:00
commit 1491dbfe86
Signed by: arno
GPG Key ID: 368DDA2E9A471EAC
12 changed files with 209 additions and 0 deletions

55
Dockerfile Normal file
View File

@ -0,0 +1,55 @@
FROM centos:7
MAINTAINER Andrey Arapov <andrey.arapov@nixaid.com>
WORKDIR /root
RUN yum -y update && \
yum -y install make gcc glibc-static
# Compile runit
# Deps: glibc-static
ENV RUNIT_NAME "runit-2.1.2"
ENV RUNIT_HASH "6fd0160cb0cf1207de4e66754b6d39750cff14bb0aa66ab49490992c0c47ba18"
RUN pushd /opt && \
curl -#L -o $RUNIT_NAME.tar.gz http://smarden.org/runit/$RUNIT_NAME.tar.gz && \
sha256sum $RUNIT_NAME.tar.gz |grep -qw $RUNIT_HASH && \
tar xf $RUNIT_NAME.tar.gz && \
rm -f $RUNIT_NAME.tar.gz && \
pushd admin/$RUNIT_NAME && \
find . -xdev -type f -name "fmt_ptime.c" -exec sed -i.orig 's;gmtime;localtime;g' '{}' \; && \
package/install && \
package/install-man
# Compile socklog
ENV SOCKLOG_NAME "socklog-2.1.0"
ENV SOCKLOG_HASH "aa869a787ee004da4e5509b5a0031bcc17a4ab4ac650c2ce8d4e488123acb455"
RUN pushd /opt && \
curl -#L -o $SOCKLOG_NAME.tar.gz http://smarden.org/socklog/$SOCKLOG_NAME.tar.gz && \
sha256sum $SOCKLOG_NAME.tar.gz |grep -qw $SOCKLOG_HASH && \
tar xf $SOCKLOG_NAME.tar.gz && \
rm -f $SOCKLOG_NAME.tar.gz && \
pushd admin/$SOCKLOG_NAME && \
package/install && \
package/install-man
# runit-docker - painlessly use Runit in Docker containers
RUN curl -#L -o runit-docker.tar.gz https://github.com/pixers/runit-docker/archive/master.tar.gz && \
tar xf runit-docker.tar.gz && \
cd runit-docker-master/ && \
make && \
make install && \
sed -i 's;runsvdir;runsvdir -P;g' /sbin/runit-docker
ENV TZ "Europe/Amsterdam"
# RUN ln -svf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
COPY service /etc/service/
RUN chmod +x -- /etc/service/*/run /etc/service/*/log/run
ENTRYPOINT ["/sbin/runit-docker"]
VOLUME ["/var/log/fakeapp1", \
"/var/log/fakeapp2"]

52
README.md Normal file
View File

@ -0,0 +1,52 @@
## show runit
This container is to show how one can use runit, svlogd and socklog in order to log the service activity.
```
$ docker run --rm -ti --name runit show-runit
/etc/service/showlog/run started
/etc/service/fakeapp3/log/run started
/etc/service/fakeapp2/log/run started
/etc/service/fakeapp1/log/run started
listening on /dev/log, gid=99, uid=99, starting.
2016-07-16_16:42:49.78418 [stdout] /etc/service/fakeapp1/fakeapp1.sh test: 1 ...
2016-07-16_16:42:51.77754 [stdout] /etc/service/fakeapp1/fakeapp1.sh test: 2 ...
2016-07-16_16:42:49.78307 [stdout] /etc/service/fakeapp2/fakeapp2.sh test: 1 ...
2016-07-16_16:42:49.78490 user.notice: Jul 16 16:42:49 /etc/service/fakeapp3/fakeapp3.sh: test: 1 ...
2016-07-16_16:42:51.78458 [stdout] /etc/service/fakeapp2/fakeapp2.sh test: 2 ...
2016-07-16_16:42:51.78676 user.notice: Jul 16 16:42:51 /etc/service/fakeapp3/fakeapp3.sh: test: 2 ...
2016-07-16_16:42:53.77904 [stdout] /etc/service/fakeapp1/fakeapp1.sh test: 3 ...
2016-07-16_16:42:53.78588 [stdout] /etc/service/fakeapp2/fakeapp2.sh test: 3 ...
2016-07-16_16:42:53.78935 user.notice: Jul 16 16:42:53 /etc/service/fakeapp3/fakeapp3.sh: test: 3 ...
2016-07-16_16:42:55.78062 [stdout] /etc/service/fakeapp1/fakeapp1.sh test: 4 ...
2016-07-16_16:42:55.78736 [stdout] /etc/service/fakeapp2/fakeapp2.sh test: 4 ...
2016-07-16_16:42:55.79176 user.notice: Jul 16 16:42:55 /etc/service/fakeapp3/fakeapp3.sh: test: 4 ...
```
## Build
```
docker build --ulimit nofile=1024:2048 -t show-runit .
```
## Use
```
docker run --rm -ti --name runit show-runit
```
```
docker run -d -ti --name runit show-runit
docker logs -f runit
docker stop runit
docker start runit
```
```
docker exec -ti runit bash
sv status /etc/service/*
sv stop /etc/service/fakeapp1
sv start /etc/service/fakeapp1
ls -la /var/log/fakeapp*
```

16
service/fakeapp1/fakeapp1.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
# fake app that logs something
c=1
while true; do
# stdout log
echo "[stdout] $0 test: $c ..."
# logger writes to syslog (/dev/log)
# logger -t $0 "test: $c ..."
c=$(($c+1))
sleep 2
done

9
service/fakeapp1/log/run Normal file
View File

@ -0,0 +1,9 @@
#!/bin/sh
# file: fakeapp1/log/run
# Collect all logs which come to stdout from the app
exec 2>&1
echo $(realpath $0) started
mkdir /var/log/fakeapp1 2>/dev/null
exec svlogd -tt /var/log/fakeapp1

5
service/fakeapp1/run Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
exec 2>&1
#exec sh -c "while true; do echo $0; sleep 1; done"
exec ./fakeapp1.sh

16
service/fakeapp2/fakeapp2.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
# fake app that logs something
c=1
while true; do
# stdout log
echo "[stdout] $0 test: $c ..."
# logger writes to syslog (/dev/log)
# logger -t $0 "test: $c ..."
c=$(($c+1))
sleep 2
done

9
service/fakeapp2/log/run Normal file
View File

@ -0,0 +1,9 @@
#!/bin/sh
# file: fakeapp2/log/run
# Collect all logs which come to stdout from the app
exec 2>&1
echo $(realpath $0) started
mkdir /var/log/fakeapp2 2>/dev/null
exec svlogd -tt /var/log/fakeapp2

5
service/fakeapp2/run Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
exec 2>&1
#exec sh -c "while true; do echo $0; sleep 1; done"
exec ./fakeapp2.sh

13
service/fakeapp3/fakeapp3.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
# fake app that logs something
c=1
while true; do
# logger writes to syslog (/dev/log)
logger -t $0 "test: $c ..."
c=$(($c+1))
sleep 2
done

13
service/fakeapp3/log/run Normal file
View File

@ -0,0 +1,13 @@
#!/bin/sh
# file: fakeapp3/log/run
# Collect all logs which come to /dev/log (syslog) from the app
exec 2>&1
echo $(realpath $0) started
mkdir /var/log/fakeapp3 2>/dev/null
# savelog -n -c 7 /var/log/fakeapp3/current
# exec sh -c "chpst -Unobody socklog unix /dev/log | tee -a /var/log/fakeapp3/current"
exec sh -c "chpst -Unobody socklog unix /dev/log | svlogd -tt /var/log/fakeapp3"

4
service/fakeapp3/run Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
exec 2>&1
exec ./fakeapp3.sh

12
service/showlog/run Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
# file: showlog/run
# Make the logs visible on `docker logs` command
exec 2>&1
echo $(realpath $0) started
# A little timeout is required, since svlogd moves current log to an archive,
# and only after that it starts logging to the "new" current log.
sleep 2
exec tail -fq /var/log/fakeapp*/current 2>/dev/null