Importing cron, rsyslog & redis-cluster(wip) Dockerfiles
This commit is contained in:
parent
8b3d7bcae9
commit
66599dacf3
5 changed files with 158 additions and 0 deletions
7
cron/Dockerfile
Normal file
7
cron/Dockerfile
Normal file
|
@ -0,0 +1,7 @@
|
|||
FROM debian:stretch
|
||||
|
||||
RUN apt update \
|
||||
&& apt install -y --no-install-recommends cron procps \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
CMD ["cron", "-f"]
|
19
redis-cluster/Dockerfile
Normal file
19
redis-cluster/Dockerfile
Normal file
|
@ -0,0 +1,19 @@
|
|||
FROM redis:4.0
|
||||
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
COPY sentinel.conf /usr/local/etc/redis/sentinel.conf
|
||||
|
||||
|
||||
ENV SENTINEL_QUORUM=2 \
|
||||
SENTINEL_DOWN_AFTER=1000 \
|
||||
SENTINEL_FAILOVER=1000 \
|
||||
REDIS_MASTER_NAME=redismaster \
|
||||
REDIS_MASTER=redis \
|
||||
REDIS_SENTINEL_IP=redissentinel \
|
||||
REDIS_SENTINEL_PORT=26379
|
||||
|
||||
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
|
||||
EXPOSE 6379
|
||||
CMD ["redis-server"]
|
107
redis-cluster/docker-entrypoint.sh
Normal file
107
redis-cluster/docker-entrypoint.sh
Normal file
|
@ -0,0 +1,107 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
count_tasks() {
|
||||
getent hosts tasks."$1" |wc -l
|
||||
}
|
||||
|
||||
# Dirty hack to ensure that "getent hosts tasks.XXXX" will list us
|
||||
sleep 3
|
||||
|
||||
|
||||
## STARTING REDIS ##
|
||||
if [ "$1" = "redis-server" ]; then
|
||||
echo "[DEBUG] PREPARING to start redis-server..."
|
||||
|
||||
# Check how many redis replicas are currently running...
|
||||
if [ "$(count_tasks redis)" -gt 1 ]; then
|
||||
# Other instances are running, we shall ask to one sentine who is master
|
||||
echo "[DEBUG] Already one redis (or more) instance running, we'll ask the master IP to a sentinel and set ourself as slave..."
|
||||
|
||||
# TODO: sanity check : Manage the case where there's no sentinel ?
|
||||
|
||||
# Wait for a sentinel to be alive
|
||||
until [ "$(redis-cli -h "$REDIS_SENTINEL_IP" -p "$REDIS_SENTINEL_PORT" ping)" = "PONG" ]; do
|
||||
echo "$REDIS_SENTINEL_IP is unavailable - sleeping"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# Get current master IP
|
||||
master_info=$(redis-cli -h "$REDIS_SENTINEL_IP" -p "$REDIS_SENTINEL_PORT" sentinel get-master-addr-by-name "$REDIS_MASTER_NAME")
|
||||
|
||||
# Ensure we have something from sentinel
|
||||
until [ "$master_info" ]; do
|
||||
echo "$REDIS_MASTER_NAME not found - sleeping"
|
||||
sleep 1
|
||||
master_info=$(redis-cli -h "$REDIS_SENTINEL_IP" -p "$REDIS_SENTINEL_PORT" sentinel get-master-addr-by-name "$REDIS_MASTER_NAME")
|
||||
done
|
||||
|
||||
master_ip=$(echo $master_info | awk '{print $1}')
|
||||
master_port=$(echo $master_info | awk '{print $2}')
|
||||
|
||||
echo "[DEBUG] STARTING redis as a SLAVE of $master_ip $master_port"
|
||||
redis-server --slaveof $master_ip $master_port
|
||||
|
||||
else
|
||||
# Only one redis - So we may be master? - TODO: Add sanity checks ?
|
||||
# Like : Is there any sentinels ? What are they doing ?...
|
||||
echo "[DEBUG] No other redis are running.... Starting redis as MASTER !!"
|
||||
exec "$@"
|
||||
|
||||
fi
|
||||
|
||||
|
||||
## STARTING SENTINEL ##
|
||||
elif [ "$1" = "redis-sentinel" ]; then
|
||||
echo "[DEBUG] PREPARING sentinel"
|
||||
|
||||
# Update config with ENV
|
||||
sed -i "s/{{ SENTINEL_QUORUM }}/$SENTINEL_QUORUM/g" /usr/local/etc/redis/sentinel.conf
|
||||
sed -i "s/{{ SENTINEL_DOWN_AFTER }}/$SENTINEL_DOWN_AFTER/g" /usr/local/etc/redis/sentinel.conf
|
||||
sed -i "s/{{ SENTINEL_FAILOVER }}/$SENTINEL_FAILOVER/g" /usr/local/etc/redis/sentinel.conf
|
||||
sed -i "s/{{ REDIS_MASTER_NAME }}/$REDIS_MASTER_NAME/g" /usr/local/etc/redis/sentinel.conf
|
||||
|
||||
# Check how many sentinels replicas are currently running...
|
||||
if [ "$(count_tasks redissentinel)" -gt 1 ]; then
|
||||
echo "[DEBUG] Already one (or more) sentinel instance running, we'll ask the master IP to a sentinel and set it as the master"
|
||||
|
||||
# Fetch sentiten
|
||||
sentinel_ips=$(getent hosts tasks.redissentinel | awk '{print $1}');
|
||||
|
||||
for ip in $sentinel_ips; do
|
||||
REDIS_IP=$(redis-cli -h "$ip" -p 26379 sentinel get-master-addr-by-name "$REDIS_MASTER_NAME" | head -1)
|
||||
echo "[DEBUG] According to sentinel at $ip - Master_info is : $REDIS_IP"
|
||||
|
||||
if [ "$REDIS_IP" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
sed -i "s/{{ REDIS_IP }}/$REDIS_IP/g" /usr/local/etc/redis/sentinel.conf
|
||||
|
||||
echo "[DEBUG] Starting sentinel with redismaster as $REDIS_IP"
|
||||
redis-server /usr/local/etc/redis/sentinel.conf --sentinel
|
||||
|
||||
else
|
||||
# No other sentinels around.
|
||||
echo "[DEBUG] No other sentinel running...."
|
||||
|
||||
# Is there redis instance running ?
|
||||
if [ "$(count_tasks redis)" -gt 1 ]; then
|
||||
# More than 1 redis running... Not so fun case to manage....
|
||||
echo "[DEBUG] More than 1 redis running - Giving up...."
|
||||
|
||||
elif [ "$(count_tasks redis)" -eq 1 ]; then
|
||||
|
||||
echo "[DEBUG] Only one redis is runnig. Let's say its a master!"
|
||||
REDIS_IP=$(getent hosts tasks.redis | awk '{print $1}');
|
||||
|
||||
sed -i "s/{{ REDIS_IP }}/$REDIS_IP/g" /usr/local/etc/redis/sentinel.conf
|
||||
redis-server /usr/local/etc/redis/sentinel.conf --sentinel
|
||||
|
||||
else
|
||||
echo "[DEBUG] No redis running... - Giving up...."
|
||||
fi;
|
||||
fi;
|
||||
fi;
|
8
redis-cluster/sentinel.conf
Normal file
8
redis-cluster/sentinel.conf
Normal file
|
@ -0,0 +1,8 @@
|
|||
port 26379
|
||||
|
||||
dir /tmp
|
||||
|
||||
sentinel monitor {{ REDIS_MASTER_NAME }} {{ REDIS_IP }} 6379 {{ SENTINEL_QUORUM }}
|
||||
sentinel down-after-milliseconds {{ REDIS_MASTER_NAME }} {{ SENTINEL_DOWN_AFTER }}
|
||||
sentinel parallel-syncs {{ REDIS_MASTER_NAME }} 1
|
||||
sentinel failover-timeout {{ REDIS_MASTER_NAME }} {{ SENTINEL_FAILOVER }}
|
17
rsyslog/Dockerfile
Normal file
17
rsyslog/Dockerfile
Normal file
|
@ -0,0 +1,17 @@
|
|||
FROM debian:stretch
|
||||
|
||||
# procps is for debugging purpose only
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends rsyslog procps \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Enable UDP syslog reception
|
||||
RUN sed -i 's/^#\(module(load="imudp")\)/\1/; s/^#\(input(type="imudp" port="514")\)/\1/' /etc/rsyslog.conf
|
||||
|
||||
# Disable kernel logging support
|
||||
RUN sed -i 's/^module(load="imklog")/#&/' /etc/rsyslog.conf
|
||||
|
||||
VOLUME /var/log/
|
||||
EXPOSE 514/udp
|
||||
|
||||
CMD /usr/sbin/rsyslogd -n
|
Loading…
Reference in a new issue