Add --restart and --recreate and always reboot on reboot argument
This commit is contained in:
parent
cdae01a6eb
commit
d356a5383d
54
provision.sh
54
provision.sh
|
@ -4,16 +4,16 @@ set -e
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf '%s\n' "Usage:"
|
printf '%s\n' "Usage:"
|
||||||
printf '$ %s\n' "$0 [-h|--help]"
|
printf '$ %s\n' "$0 [--help]"
|
||||||
printf '$ %s\n' "$0 [--dry] os"
|
printf '$ %s\n' "$0 [--dry] os"
|
||||||
printf '$ %s\n' "$0 [--dry] base"
|
printf '$ %s\n' "$0 [--dry] base"
|
||||||
printf '$ %s\n' "$0 [--dry] firewall"
|
printf '$ %s\n' "$0 [--dry] firewall"
|
||||||
printf '$ %s\n' "$0 [--dry] ssh"
|
printf '$ %s\n' "$0 [--dry] ssh"
|
||||||
printf '$ %s\n' "$0 [--dry] docker"
|
printf '$ %s\n' "$0 [--dry] docker"
|
||||||
printf '$ %s\n' "$0 [--dry] docker_config"
|
printf '$ %s\n' "$0 [--dry] docker_config"
|
||||||
printf '$ %s\n' "$0 [--dry] users [-i|--init]"
|
printf '$ %s\n' "$0 [--dry] users [--init]"
|
||||||
printf '$ %s\n' "$0 [--dry] reboot [-f|--force]"
|
printf '$ %s\n' "$0 [--dry] reboot"
|
||||||
printf '$ %s\n' "$0 [--dry] services [-d|--down] [SINGLE_SERVICE]"
|
printf '$ %s\n' "$0 [--dry] services [--down|--restart|--recreate] [SINGLE_SERVICE]"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_modules() {
|
install_modules() {
|
||||||
|
@ -39,46 +39,52 @@ fi
|
||||||
|
|
||||||
case $TAG in
|
case $TAG in
|
||||||
"")
|
"")
|
||||||
install_modules; $BASE_CMD ;;
|
install_modules; $EXEC "$BASE_CMD" ;;
|
||||||
os|base|firewall|ssh|docker|docker_config)
|
os|base|firewall|ssh|docker|docker_config)
|
||||||
install_modules; $BASE_CMD --tags "$TAG" ;;
|
install_modules; $EXEC "$BASE_CMD --tags '$TAG'" ;;
|
||||||
users)
|
users)
|
||||||
install_modules
|
install_modules
|
||||||
|
|
||||||
if [ "$1" = "-i" ] || [ "$1" = "--init" ]; then
|
if [ "$1" = "--init" ]; then
|
||||||
$EXEC "$BASE_CMD --user root --tags '$TAG'"
|
$EXEC "$BASE_CMD --user root --tags '$TAG'"
|
||||||
else
|
else
|
||||||
$EXEC "$BASE_CMD --tags '$TAG'"
|
$EXEC "$BASE_CMD --tags '$TAG'"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
reboot)
|
reboot)
|
||||||
install_modules
|
install_modules; $EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'do_reboot=true'" ;;
|
||||||
|
|
||||||
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
|
|
||||||
$EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'force_reboot=true'"
|
|
||||||
else
|
|
||||||
$EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'reboot=true'"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
services)
|
services)
|
||||||
install_modules
|
install_modules
|
||||||
|
|
||||||
if [ "$1" = "-d" ] || [ "$1" = "--down" ]; then
|
if [ "$1" = "--down" ]; then
|
||||||
DOWN=1
|
ACTION="down"
|
||||||
|
shift
|
||||||
|
elif [ "$1" = "--restart" ]; then
|
||||||
|
ACTION="restart"
|
||||||
|
shift
|
||||||
|
elif [ "$1" = "--recreate" ]; then
|
||||||
|
ACTION="recreate"
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$DOWN" ] && [ -n "$1" ]; then
|
case $1 in
|
||||||
VARS="single_service=$1"
|
--*)
|
||||||
elif [ -n "$DOWN" ] && [ -z "$1" ]; then
|
;;
|
||||||
VARS="stop=true"
|
*)
|
||||||
elif [ -n "$DOWN" ] && [ -n "$1" ]; then
|
SINGLE_SERVICE="$1" ;;
|
||||||
VARS='{"stop": true, "single_service": "'$1'"}'
|
esac
|
||||||
|
|
||||||
|
if [ -z "$ACTION" ] && [ -n "$SINGLE_SERVICE" ]; then
|
||||||
|
VARS="single_service=$SINGLE_SERVICE"
|
||||||
|
elif [ -n "$ACTION" ] && [ -z "$SINGLE_SERVICE" ]; then
|
||||||
|
VARS="$ACTION=true"
|
||||||
|
elif [ -n "$ACTION" ] && [ -n "$SINGLE_SERVICE" ]; then
|
||||||
|
VARS='{"'$ACTION'": true, "single_service": "'$SINGLE_SERVICE'"}'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$EXEC "$BASE_CMD --tags '$TAG' $(test -z "$VARS" || echo "--extra-vars '$VARS'")"
|
$EXEC "$BASE_CMD --tags '$TAG' $(test -z "$VARS" || echo "--extra-vars '$VARS'")"
|
||||||
;;
|
;;
|
||||||
-h|--help)
|
--help)
|
||||||
usage ;;
|
usage ;;
|
||||||
*)
|
*)
|
||||||
usage >&2; exit 1 ;;
|
usage >&2; exit 1 ;;
|
||||||
|
|
|
@ -22,8 +22,9 @@
|
||||||
- name: Deploy Caddy Docker container
|
- name: Deploy Caddy Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: caddy
|
name: caddy
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: caddy:{{ services.caddy.version }}
|
image: caddy:{{ services.caddy.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
default_host_ip: ''
|
default_host_ip: ''
|
||||||
|
|
|
@ -28,8 +28,9 @@
|
||||||
- name: Deploy Jitsi Meet with Docker Compose
|
- name: Deploy Jitsi Meet with Docker Compose
|
||||||
community.docker.docker_compose:
|
community.docker.docker_compose:
|
||||||
project_name: jitsi_meet
|
project_name: jitsi_meet
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'present' }}"
|
state: "{{ 'absent' if down is defined and down else 'present' }}"
|
||||||
restarted: "{{ stop is undefined or not stop }}"
|
restarted: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ 'always' if recreate is defined and recreate else 'smart' }}"
|
||||||
remove_orphans: true
|
remove_orphans: true
|
||||||
pull: true
|
pull: true
|
||||||
definition:
|
definition:
|
||||||
|
@ -113,5 +114,5 @@
|
||||||
container: jitsi_meet_prosody_1
|
container: jitsi_meet_prosody_1
|
||||||
command: |
|
command: |
|
||||||
/usr/bin/prosodyctl --config /config/prosody.cfg.lua register {{ services.jitsi_meet.username }} meet.jitsi {{ secrets.jitsi_meet.password }}
|
/usr/bin/prosodyctl --config /config/prosody.cfg.lua register {{ services.jitsi_meet.username }} meet.jitsi {{ secrets.jitsi_meet.password }}
|
||||||
when: (stop is undefined or not stop) and
|
when: (down is undefined or not down) and
|
||||||
not jitsi_meet_user.stat.exists
|
not jitsi_meet_user.stat.exists
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
- name: Deploy Lingva Docker container
|
- name: Deploy Lingva Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: lingva
|
name: lingva
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: thedaviddelta/lingva-translate:{{ services.lingva.version }}
|
image: thedaviddelta/lingva-translate:{{ services.lingva.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
env:
|
env:
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
- name: Deploy samsapti.dev Docker container
|
- name: Deploy samsapti.dev Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: samsapti.dev
|
name: samsapti.dev
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: nginx:{{ services.samsapti_dev.version }}
|
image: nginx:{{ services.samsapti_dev.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
networks:
|
networks:
|
||||||
|
|
|
@ -32,8 +32,9 @@
|
||||||
- name: Deploy SearXNG with Docker Compose
|
- name: Deploy SearXNG with Docker Compose
|
||||||
community.docker.docker_compose:
|
community.docker.docker_compose:
|
||||||
project_name: searxng
|
project_name: searxng
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'present' }}"
|
state: "{{ 'absent' if down is defined and down else 'present' }}"
|
||||||
restarted: "{{ stop is undefined or not stop }}"
|
restarted: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ 'always' if recreate is defined and recreate else 'smart' }}"
|
||||||
remove_orphans: true
|
remove_orphans: true
|
||||||
pull: true
|
pull: true
|
||||||
definition:
|
definition:
|
||||||
|
|
|
@ -15,8 +15,9 @@
|
||||||
- name: Deploy SMP server Docker container
|
- name: Deploy SMP server Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: smp-server
|
name: smp-server
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: simplexchat/smp-server:{{ services.simplexmq_smp.version }}
|
image: simplexchat/smp-server:{{ services.simplexmq_smp.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
default_host_ip: ''
|
default_host_ip: ''
|
||||||
|
|
|
@ -16,8 +16,9 @@
|
||||||
- name: Deploy XFTP server Docker container
|
- name: Deploy XFTP server Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: xftp-server
|
name: xftp-server
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: simplexchat/xftp-server:{{ services.simplexmq_xftp.version }}
|
image: simplexchat/xftp-server:{{ services.simplexmq_xftp.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
default_host_ip: ''
|
default_host_ip: ''
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
- name: Deploy Tor Docker container
|
- name: Deploy Tor Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: tor
|
name: tor
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: goldy/tor-hidden-service:{{ services.tor.version }}
|
image: goldy/tor-hidden-service:{{ services.tor.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
env:
|
env:
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
- name: Deploy Watchtower Docker container
|
- name: Deploy Watchtower Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: watchtower
|
name: watchtower
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: containrrr/watchtower:{{ services.watchtower.version }}
|
image: containrrr/watchtower:{{ services.watchtower.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
networks:
|
networks:
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
- name: Deploy WKD Docker container
|
- name: Deploy WKD Docker container
|
||||||
community.docker.docker_container:
|
community.docker.docker_container:
|
||||||
name: wkd
|
name: wkd
|
||||||
state: "{{ 'absent' if stop is defined and stop else 'started' }}"
|
state: "{{ 'absent' if down is defined and down else 'started' }}"
|
||||||
restart: "{{ stop is undefined or not stop }}"
|
restart: "{{ restart is defined and restart }}"
|
||||||
|
recreate: "{{ recreate is defined and recreate }}"
|
||||||
image: nginx:{{ services.wkd.version }}
|
image: nginx:{{ services.wkd.version }}
|
||||||
restart_policy: always
|
restart_policy: always
|
||||||
networks:
|
networks:
|
||||||
|
|
|
@ -12,17 +12,12 @@
|
||||||
apply:
|
apply:
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
vars:
|
vars:
|
||||||
stop: true
|
down: true
|
||||||
when: needs_reboot.stat.exists or
|
when: needs_reboot.stat.exists or
|
||||||
(force_reboot is defined and force_reboot)
|
(do_reboot is defined and do_reboot)
|
||||||
|
|
||||||
- name: Reboot host
|
- name: Reboot host
|
||||||
ansible.builtin.reboot:
|
ansible.builtin.reboot:
|
||||||
when: needs_reboot.stat.exists or
|
when: needs_reboot.stat.exists or
|
||||||
(force_reboot is defined and force_reboot)
|
(do_reboot is defined and do_reboot)
|
||||||
register: rebooted
|
register: rebooted
|
||||||
|
|
||||||
- name: End play if reboot is not needed
|
|
||||||
ansible.builtin.meta: end_play
|
|
||||||
when: reboot is defined and reboot and
|
|
||||||
(rebooted.rebooted is undefined or not rebooted.rebooted)
|
|
||||||
|
|
Reference in a new issue