Add full affine scripts

This commit is contained in:
2025-05-04 20:39:25 +02:00
parent dbd5a510bd
commit 43705e2799
3 changed files with 129 additions and 12 deletions

View File

@@ -3,21 +3,34 @@ set -e
. ./env.sh
if systemctl --user list-units --full --all | grep -q "$CONTAINER_PREFIX-$CONTAINER_SERVER.service"; then
systemctl --user stop $CONTAINER_PREFIX-$CONTAINER_SERVER.service
fi
services=("$CONTAINER_PREFIX-$CONTAINER_SERVER.service"
"$CONTAINER_PREFIX-$CONTAINER_POSTGRES.service"
"$CONTAINER_PREFIX-$CONTAINER_REDIS.service"
)
if systemctl --user list-units --full --all | grep -q "$CONTAINER_PREFIX-$CONTAINER_POSTGRES.service"; then
systemctl --user stop $CONTAINER_PREFIX-$CONTAINER_POSTGRES.service
fi
for service in "${services[@]}"; do
if systemctl --user list-units --full --all | grep -q "$service"; then
echo "Stopping $service..."
systemctl --user stop $service
echo "$service stopped."
fi
done
if systemctl --user list-units --full --all | grep -q "$CONTAINER_PREFIX-$CONTAINER_REDIS.service"; then
systemctl --user stop $CONTAINER_PREFIX-$CONTAINER_REDIS.service
fi
containers=(
"$CONTAINER_SERVER",
"$CONTAINER_POSTGRES",
"$CONTAINER_REDIS"
)
if ! podman network exists $NETWORK; then
podman network create $NETWORK
for container in "${containers[@]}"; do
if podman container exists "$containers"; then
echo "Stop and delete existing container $containers"
if podman inspect -f '{{.State.Running}}' "$containers" | grep -q true; then
podman stop "$containers"
fi
podman rm "$containers"
fi
done
mkdir -p ./systemd-units
podman create \
@@ -136,4 +149,21 @@ EOF
)
echo "$BACKEND_CFG" | sudo tee $SERVICE_DIR/backend.block > /dev/null
sudo loginctl enable-linger $USER
sudo loginctl enable-linger $USER
echo "Generate backup script"
BACKUP_FILE="affine_backup.sh"
cp backup.sh $BACKUP_FILE
sed -i "s|^UPLOAD=\"\"|UPLOAD=\"$UPLOAD_LOCATION\"|" "$BACKUP_FILE"
sed -i "s|^CONFIG=\"\"|CONFIG=\"$CONFIG_LOCATION\"|" "$BACKUP_FILE"
sed -i "s|^DB_USERNAME=\"\"|DB_USERNAME=\"$DB_USERNAME\"|" "$BACKUP_FILE"
sed -i "s|^DB_DATABASE=\"\"|DB_DATABASE=\"$DB_DATABASE\"|" "$BACKUP_FILE"
sed -i "s|^LOCAL_BACKUP=\"\$HOME/.local/backup\"|LOCAL_BACKUP=\"\$HOME/.local/backup/$CONTAINER_PREFIX\"|" "$BACKUP_FILE"
sed -i "s|^CONTAINER_POSTGRES=\"\"|CONTAINER_POSTGRES=\"$CONTAINER_POSTGRES\"|" "$BACKUP_FILE"
sed -i "s|^REMOTE=\"\"|REMOTE=\"$BACKUP_REMOTE\"|" "$BACKUP_FILE"
sed -i "s|^SERVICE_SERVER=\"\"|SERVICE_SERVER=\"${CONTAINER_PREFIX}-${CONTAINER_SERVER}.service\"|" "$BACKUP_FILE"
mv $BACKUP_FILE $AFFINE_ROOT
(crontab -l 2>/dev/null; echo "0 3 * * * $AFFINE_ROOT/$BACKUP_FILE") | crontab -
echo "Deploy completed, manually run haproxy to generate new config."