#!/bin/bash

# This script 
# - reload system daemon
#   to reload it with the /etc/systemd/system/containerd.service.d/override.conf installed by xivo-docker package
# - and restarts containerd service
#   to ensure it is taken into account
# This is to workaround the change in the LimitNOFILE introduced by containerd.io 2.x (see #8775)

display_service_limitNOFILE() {
    local service="${1}"; shift

    systemctl show "${service}" --property=LimitNOFILE --property=LimitNOFILESoft
}

if dpkg --compare-versions "$XIVOCC_VERSION_INSTALLED" "<<" "2025.11.00"; then
    echo "Current LimitNOFILE config for containerd.service:"
    display_service_limitNOFILE containerd.service
    systemctl daemon-reload
    systemctl restart containerd.service
    echo "New LimitNOFILE applied to containerd.service:"
    display_service_limitNOFILE containerd.service
    exit 0
else
    echo "Current LimitNOFILE config for containerd.service:"
    display_service_limitNOFILE containerd.service
    exit 0
fi
