Skip to content

Commit

Permalink
Handle deployment abnormalities
Browse files Browse the repository at this point in the history
  • Loading branch information
plengauer authored Mar 10, 2024
1 parent 2a92815 commit 1fb9b3b
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Deployment/Baremetal/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: philbot-baremetal
Provides: philbot-deployment
Version: 2.5.1
Version: 2.6.0
Architecture: all
Depends: philbot-config (>= 4.0.0), bash, cron, wget, tar, jq, ruby, ruby-bundler, nodejs (>= 20.0.0), npm, python3, python3-pip, python3-venv, libopusfile0, ffmpeg, curl, iptables-persistent, opentelemetry-shell (>= 2.4.3)
Conflicts: philbot-containerized, philbot-k8s
Expand Down
37 changes: 19 additions & 18 deletions Deployment/Baremetal/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#!/bin/bash -e
source /usr/bin/philbot_init_otel

if [ "$1" = "triggered" ]; then
philbot_stop
if [ "$1" = 'abort-configure' ] || [ "$1" = 'abort-upgrade' ] || [ "$1" = 'abort-remove' ] || [ "$1" = 'abort-deconfigure' ]; then
exit 0
elif [ "$1" = 'triggered' ] || [ "$1" = 'reconfigure' ]; then
philbot_config_populate
philbot_restart
elif [ "$1" = 'configure' ]; then
philbot_config_populate
source /usr/bin/philbot_init_otel
wget -O /opt/philbot/libopus.tar.bz2 https://anaconda.org/anaconda/libopus/1.3/download/linux-64/libopus-1.3-h7b6447c_0.tar.bz2
tar -xf /opt/philbot/libopus.tar.bz2 -C /opt/philbot
rm /opt/philbot/libopus.tar.bz2
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 4443
iptables-save > /etc/iptables/rules.v4
systemctl daemon-reload
systemctl enable philbot_scheduler philbot_discordgateway2http philbot_backend philbot_voice
philbot_start
else
exit 1
fi

philbot_config_populate
source /usr/bin/philbot_init_otel

wget -O /opt/philbot/libopus.tar.bz2 https://anaconda.org/anaconda/libopus/1.3/download/linux-64/libopus-1.3-h7b6447c_0.tar.bz2
tar -xf /opt/philbot/libopus.tar.bz2 -C /opt/philbot
rm /opt/philbot/libopus.tar.bz2

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 4443
iptables-save > /etc/iptables/rules.v4

systemctl daemon-reload
systemctl enable philbot_scheduler philbot_discordgateway2http philbot_backend philbot_voice
philbot_start
14 changes: 9 additions & 5 deletions Deployment/Baremetal/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/bin/bash
#!/bin/bash -e
if [ -f /usr/bin/philbot_init_otel ]; then
source /usr/bin/philbot_init_otel
fi
systemctl daemon-reload
if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
rm -rf /opt/philbot
if [ "$1" = 'remove' ] || [ "$1" = 'purge' ] || [ "$1" = 'disappear' ]; then
rm -rf /opt/philbot /var/lib/philbot/collector.yaml /var/lib/philbot/environment.properties.*
elif [ "$1" = 'upgrade' ]; then
true
elif [ "$1" = 'failed-upgrade' ] || [ "$1" = 'abort-install' ] || [ "$1" = 'abort-upgrade' ]; then
true
else
exit 1
fi
rm /var/lib/philbot/collector.yaml /var/lib/philbot/environment.properties.*
exit 0
13 changes: 10 additions & 3 deletions Deployment/Baremetal/DEBIAN/preinst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/bash
#!/bin/bash -e
if [ -f /usr/bin/philbot_init_otel ]; then
source /usr/bin/philbot_init_otel
fi
philbot_stop
exit 0
if [ "$1" = 'install' ]; then
true
elif [ "$1" = 'upgrade' ]; then
philbot_stop
elif [ "$1" = 'abort-upgrade' ]; then
philbot_start || true
else
exit 1
fi
13 changes: 9 additions & 4 deletions Deployment/Baremetal/DEBIAN/prerm
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash
#!/bin/bash -e
source /usr/bin/philbot_init_otel
philbot_stop
systemctl disable philbot_scheduler philbot_discordgateway2http philbot_backend philbot_voice
exit 0
if [ "$1" = 'remove' ] || [ "$1" = 'upgrade' ] || [ "$1" = 'deconfigure' ]; then
philbot_stop
systemctl disable philbot_scheduler philbot_discordgateway2http philbot_backend philbot_voice
elif [ "$1" = 'failed-upgrade' ]; then
philbot_start || true
else
exit 1
fi
3 changes: 1 addition & 2 deletions Deployment/Containerized/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Package: philbot-containerized
Provides: philbot-deployment
Version: 2.8.10
Version: 2.9.0
Architecture: all
Depends: philbot-config (>= 4.0.0), debconf, bash, parallel, cron, wget, docker.io, iptables-persistent, jq, opentelemetry-shell (>= 2.6.1)
Conflicts: philbot-baremetal, philbot-k8s
Priority: extra
Maintainer: Philipp Lengauer <[email protected]>
Homepage: https://github.com/plengauer/Philbot
Description: Philbot as containerized installation, bot will auto-update

79 changes: 36 additions & 43 deletions Deployment/Containerized/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
#!/bin/bash -e
source /usr/bin/philbot_init_otel

if [ "$1" = "triggered" ]; then
philbot_stop >&2
if [ "$1" = 'abort-configure' ] || [ "$1" = 'abort-upgrade' ] || [ "$1" = 'abort-remove' ] || [ "$1" = 'abort-deconfigure' ]; then
true
elif [ "$1" = 'triggered' ] || [ "$1" = 'reconfigure' ]; then
philbot_config_populate
philbot_stop
philbot_start
elif [ "$1" = 'configure' ]; then
philbot_config_populate
source /usr/bin/philbot_init_otel
echo "OPENTELEMETRY_TRACES_API_ENDPOINT=http://127.0.0.1:4318/v1/traces" >> /var/lib/philbot/environment.properties.scheduler
echo "OPENTELEMETRY_TRACES_API_ENDPOINT=http://127.0.0.1:4318/v1/traces" >> /var/lib/philbot/environment.properties.discordgateway2http
echo "OPENTELEMETRY_TRACES_API_ENDPOINT=http://127.0.0.1:4318/v1/traces" >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
echo "OPENTELEMETRY_TRACES_API_ENDPOINT=http://127.0.0.1:4318/v1/traces" >> /var/lib/philbot/environment.properties.backend
echo "OPENTELEMETRY_TRACES_API_ENDPOINT=http://127.0.0.1:4318/v1/traces" >> /var/lib/philbot/environment.properties.voice
echo "OPENTELEMETRY_METRICS_API_ENDPOINT=http://127.0.0.1:4318/v1/metrics" >> /var/lib/philbot/environment.properties.scheduler
echo "OPENTELEMETRY_METRICS_API_ENDPOINT=http://127.0.0.1:4318/v1/metrics" >> /var/lib/philbot/environment.properties.discordgateway2http
echo "OPENTELEMETRY_METRICS_API_ENDPOINT=http://127.0.0.1:4318/v1/metrics" >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
echo "OPENTELEMETRY_METRICS_API_ENDPOINT=http://127.0.0.1:4318/v1/metrics" >> /var/lib/philbot/environment.properties.backend
echo "OPENTELEMETRY_METRICS_API_ENDPOINT=http://127.0.0.1:4318/v1/metrics" >> /var/lib/philbot/environment.properties.voice
echo "OPENTELEMETRY_LOGS_API_ENDPOINT=http://127.0.0.1:4318/v1/logs" >> /var/lib/philbot/environment.properties.scheduler
echo "OPENTELEMETRY_LOGS_API_ENDPOINT=http://127.0.0.1:4318/v1/logs" >> /var/lib/philbot/environment.properties.discordgateway2http
echo "OPENTELEMETRY_LOGS_API_ENDPOINT=http://127.0.0.1:4318/v1/logs" >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
echo "OPENTELEMETRY_LOGS_API_ENDPOINT=http://127.0.0.1:4318/v1/logs" >> /var/lib/philbot/environment.properties.backend
echo "OPENTELEMETRY_LOGS_API_ENDPOINT=http://127.0.0.1:4318/v1/logs" >> /var/lib/philbot/environment.properties.voice
. /usr/share/debconf/confmodule
config() { db_get philbot-containerized/"$*"; echo "$*=$RET"; }
config SHARD_COUNT_MIN >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
config SHARD_COUNT_MAX >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
config SHARD_COUNT_REDUNDANT >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
db_stop
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 4443
iptables-save > /etc/iptables/rules.v4
if [ ! -f "/opt/philbot/shards" ]; then echo "SHARD_COUNT=0" > /opt/philbot/shards; fi
philbot_start >&2
curl -v http://127.0.0.1:8080/invite 2>&1 | grep location | rev | cut -d' ' -f1 | rev | xargs echo 'Invite with' >&2
fi

philbot_config_populate
source /usr/bin/philbot_init_otel

echo "OPENTELEMETRY_TRACES_API_ENDPOINT=http://127.0.0.1:4318/v1/traces" >> /var/lib/philbot/environment.properties.scheduler
echo "OPENTELEMETRY_TRACES_API_ENDPOINT=http://127.0.0.1:4318/v1/traces" >> /var/lib/philbot/environment.properties.discordgateway2http
echo "OPENTELEMETRY_TRACES_API_ENDPOINT=http://127.0.0.1:4318/v1/traces" >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
echo "OPENTELEMETRY_TRACES_API_ENDPOINT=http://127.0.0.1:4318/v1/traces" >> /var/lib/philbot/environment.properties.backend
echo "OPENTELEMETRY_TRACES_API_ENDPOINT=http://127.0.0.1:4318/v1/traces" >> /var/lib/philbot/environment.properties.voice
echo "OPENTELEMETRY_METRICS_API_ENDPOINT=http://127.0.0.1:4318/v1/metrics" >> /var/lib/philbot/environment.properties.scheduler
echo "OPENTELEMETRY_METRICS_API_ENDPOINT=http://127.0.0.1:4318/v1/metrics" >> /var/lib/philbot/environment.properties.discordgateway2http
echo "OPENTELEMETRY_METRICS_API_ENDPOINT=http://127.0.0.1:4318/v1/metrics" >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
echo "OPENTELEMETRY_METRICS_API_ENDPOINT=http://127.0.0.1:4318/v1/metrics" >> /var/lib/philbot/environment.properties.backend
echo "OPENTELEMETRY_METRICS_API_ENDPOINT=http://127.0.0.1:4318/v1/metrics" >> /var/lib/philbot/environment.properties.voice
echo "OPENTELEMETRY_LOGS_API_ENDPOINT=http://127.0.0.1:4318/v1/logs" >> /var/lib/philbot/environment.properties.scheduler
echo "OPENTELEMETRY_LOGS_API_ENDPOINT=http://127.0.0.1:4318/v1/logs" >> /var/lib/philbot/environment.properties.discordgateway2http
echo "OPENTELEMETRY_LOGS_API_ENDPOINT=http://127.0.0.1:4318/v1/logs" >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
echo "OPENTELEMETRY_LOGS_API_ENDPOINT=http://127.0.0.1:4318/v1/logs" >> /var/lib/philbot/environment.properties.backend
echo "OPENTELEMETRY_LOGS_API_ENDPOINT=http://127.0.0.1:4318/v1/logs" >> /var/lib/philbot/environment.properties.voice

. /usr/share/debconf/confmodule
config() {
db_get philbot-containerized/"$*"
echo "$*=$RET"
}
config SHARD_COUNT_MIN >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
config SHARD_COUNT_MAX >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
config SHARD_COUNT_REDUNDANT >> /var/lib/philbot/environment.properties.discordgateway2httpmaster
db_stop

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 4443
iptables-save > /etc/iptables/rules.v4

if [ ! -f "/opt/philbot/shards" ]; then
echo "SHARD_COUNT=0" > /opt/philbot/shards
fi
philbot_start >&2

curl -v http://127.0.0.1:8080/invite 2>&1 | grep location | rev | cut -d' ' -f1 | rev | xargs echo 'Invite with' >&2
13 changes: 9 additions & 4 deletions Deployment/Containerized/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/bash
#!/bin/bash -e
if [ -f /usr/bin/philbot_init_otel ]; then
source /usr/bin/philbot_init_otel
fi
if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
if [ "$1" = 'remove' ] || [ "$1" = 'purge' ] || [ "$1" = 'disappear' ]; then
rm /opt/philbot/shards /var/lib/philbot/collector.yaml /var/lib/philbot/environment.properties.*
docker image prune --all --force
elif [ "$1" = 'upgrade' ]; then
true
elif [ "$1" = 'failed-upgrade' ] || [ "$1" = 'abort-install' ] || [ "$1" = 'abort-upgrade' ]; then
true
else
exit 1
fi
rm /opt/philbot/shards /var/lib/philbot/collector.yaml /var/lib/philbot/environment.properties.*
exit 0
11 changes: 8 additions & 3 deletions Deployment/Containerized/DEBIAN/preinst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash
#!/bin/bash -e
if [ -f /usr/bin/philbot_init_otel ]; then
source /usr/bin/philbot_init_otel
fi
philbot_stop
exit 0
if [ "$1" = 'install' ] || [ "$1" = 'upgrade' ]; then
philbot_stop
elif [ "$1" = 'abort-upgrade' ]; then
philbot_start || true
else
exit 1
fi
8 changes: 7 additions & 1 deletion Deployment/Containerized/DEBIAN/prerm
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/bin/bash -e
source /usr/bin/philbot_init_otel
philbot_stop
if [ "$1" = 'remove' ] || [ "$1" = 'upgrade' ] || [ "$1" = 'deconfigure' ]; then
philbot_stop
elif [ "$1" = 'failed-upgrade' ]; then
philbot_start || true
else
exit 1
fi

0 comments on commit 1fb9b3b

Please sign in to comment.