Ultima attività 6 months ago

Revisione f7590577ba90a14ccb78b7329d0d3702d5d9fd57

add_healthcheack.sh Raw
1#!/bin/bash
2DOCKER_BASE=/srv/docker
3
4mkdir -p ${DOCKER_BASE}/watchtower/container.conf
5
6[ $(grep -c "healthcheck:" ${DOCKER_BASE}/watchtower/container.conf/production.yml) -eq 0 ] && sed -i '/labels:/i\ healthcheck:\n\ test: ["CMD", "/watchtower", "--health-check"]\n\ interval: 30s\n\ timeout: 10s\n\ retries: 3\n\ start_period: 40s' ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml && cd ${DOCKER_BASE}/watchtower/ && docker-compose -f docker-compose.yml -f container.conf/production.yml config && systemctl restart watchtower
7
deploy_watchtower.sh Raw
1#!/bin/bash
2DOCKER_BASE=/srv/docker
3
4mkdir -p ${DOCKER_BASE}/watchtower/container.conf
5
6cat > ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml <<EOF
7version: '3.7'
8
9services:
10 watchtower:
11 image: ghcr.io/nicholas-fedor/watchtower
12 healthcheck:
13 test:
14 - CMD
15 - /watchtower
16 - --health-check
17 timeout: 10s
18 interval: 30s
19 retries: 3
20 start_period: 40s
21 labels:
22 com.centurylinklabs.watchtower.enable: "true"
23 restart: on-failure
24 volumes:
25 - /var/run/docker.sock:/var/run/docker.sock
26 - /etc/localtime:/etc/localtime:ro
27 - /etc/timezone:/etc/timezone:ro
28 command: --interval 3600 --label-enable
29EOF
30ln -s container.conf/docker-compose.yml ${DOCKER_BASE}/watchtower/
31
32cat > ${DOCKER_BASE}/watchtower/container.conf/production.yml <<EOF
33version: '3.7'
34EOF
35
36cat > ${DOCKER_BASE}/watchtower/container.conf/watchtower.service <<EOF
37[Unit]
38Description=Watchtower Service
39After=network.target docker.service
40Requires=docker.service
41
42[Service]
43Type=oneshot
44RemainAfterExit=yes
45
46Environment="WORK_DIR=/srv/docker/watchtower/"
47WorkingDirectory=/srv/docker/watchtower/
48ExecStartPre=-/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down
49ExecStartPre=-/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" pull
50ExecStart=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" up -d
51ExecStop=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down
52
53[Install]
54WantedBy=docker.service
55EOF
56ln -s ${DOCKER_BASE}/watchtower/container.conf/watchtower.service /etc/systemd/system/
57
58systemctl daemon-reload && systemctl enable watchtower && systemctl start watchtower
59
migrate_1.1.6_notifcations.sh Raw
1#!/bin/bash
2DOCKER_BASE=/srv/docker
3WATCHTOWER_PATH=${DOCKER_BASE}/watchtower
4DC_COMMAND="docker-compose -f docker-compose.yml"
5
6cd ${WATCHTOWER_PATH} || exit
7[ -f container.conf/production.yml ] && DC_COMMAND="${DC_COMMAND} -f container.conf/production.yml"
8[ "$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATIONS" | awk '{print $2}')" != "email" ] && exit
9cp container.conf/production.yml container.conf/production.yml.old
10
11SMTP_HOST="$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATION_EMAIL_SERVER:" | awk '{print $2}')"
12SMTP_FROM="$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATION_EMAIL_FROM:" | awk '{print $2}')"
13SMTP_TO="$(${DC_COMMAND} config | grep "WATCHTOWER_NOTIFICATION_EMAIL_TO:" | awk '{print $2}')"
14
15[ ! -e ${WATCHTOWER_PATH}/.env ] && ln -s container.conf/.env ${WATCHTOWER_PATH}/.env
16touch ${WATCHTOWER_PATH}/container.conf/.env
17sed -iE '/^SMTP_/d' ${WATCHTOWER_PATH}/container.conf/.env
18cat >> ${WATCHTOWER_PATH}/container.conf/.env <<EOF
19SMTP_HOST=${SMTP_HOST}
20SMTP_FROM=${SMTP_FROM}
21SMTP_TO=${SMTP_TO}
22EOF
23
24sed -i 's/WATCHTOWER_NOTIFICATIONS.*email/WATCHTOWER_NOTIFICATIONS=shoutrrr/' ${WATCHTOWER_PATH}/container.conf/production.yml
25sed -i 's#WATCHTOWER_NOTIFICATION_EMAIL_FROM.*"#WATCHTOWER_NOTIFICATION_URL=smtp://:@\${SMTP_HOST}/?auth=None\&encryption=None\&fromaddress=\${SMTP_FROM}\&fromname=Watchtower\&starttls=No\&toaddresses=\${SMTP_TO}\&usehtml=No"#' ${WATCHTOWER_PATH}/container.conf/production.yml
26sed -iE '/WATCHTOWER_NOTIFICATION_EMAIL_/d' ${WATCHTOWER_PATH}/container.conf/production.yml
27
migrate_to_containrrr.sh Raw
1#!/bin/bash
2DOCKER_BASE=/srv/docker
3
4mkdir -p ${DOCKER_BASE}/watchtower/container.conf
5
6sed -i s/v2tec/containrrr/g ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml
7
8systemctl restart watchtower && docker image rm v2tec/watchtower
9
migrate_to_image_nicholas-fedor.sh Raw
1#!/bin/bash
2DOCKER_BASE=/srv/docker
3
4mkdir -p ${DOCKER_BASE}/watchtower/container.conf
5
6sed -i "s/image: containrrr\/watchtower/image: ghcr.io\/nicholas-fedor\/watchtower/" ${DOCKER_BASE}/watchtower/container.conf/docker-compose.yml && cd ${DOCKER_BASE}/watchtower && systemctl restart watchtower && docker-compose -f docker-compose.yml -f container.conf/production.yml logs -f; docker image rm containrrr/watchtower
7