HEX
Server: Apache
System: Linux SH-FR-PM-y8qo 6.6.80-paas #1 SMP PREEMPT_DYNAMIC Thu Sep 25 11:18:23 UTC 2025 x86_64
User: hosting-user (5000)
PHP: 8.3.28
Disabled: NONE
Upload Files
File: //srv/admin/scripts/kill-lib.sh
#!/bin/bash -e

source /srv/admin/scripts/init-lib.sh
source /srv/admin/scripts/logrotate_inc.sh

# On child death, checks PIDs, if so aborts.
function on_child_death() {
    trap - CHLD
    check_daemons
    trap on_child_death CHLD
}

function check_daemons() {
    local daemon=
    echo -n "checking if daemons are running..."
    foreach_daemon --doublecheck status || {
        echo "Process $daemon died ! Aborting."
        ps ax
        exit 1
    }
    echo ok
}

function on_sigterm() {
    exit 0
}

# Removes temporary files and kills processes when done
function on_exit() {
    trap - EXIT CHLD

    echo "shutdown"
    foreach_daemon --force stop
}

function on_err() {
    local exitcode="$1"
    local filename="$2"
    local lineno="$3"

    echo "command '$BASH_COMMAND' exited" \
        "with status code $exitcode at $filename:$lineno"
}

# Reloads application signal
function on_sigusr1() {
    case "$WWW_ENGINE" in
        nodejs)
            /srv/admin/scripts/init.d/nodejs restart
            ;;
        python|ruby)
            "/srv/admin/scripts/init.d/$WWW_ENGINE" restart
            ;;
    esac
}

function admin_cron() {
    do_as ${SYS_USER} /opt/anacron/usr/sbin/anacron -dqsn -S /srv/data/var/cron/admin -t /srv/admin/configs/cron/anacrontab -o /srv/data/var/log/cron/admin.log
}

function user_cron() {
    do_as "$PAAS_USER" /srv/admin/scripts/anacron_user.sh
}

function on_cron() {
    if [ "$DB_ENGINE" = mysql ]; then
        # this is error prone due to bad usage of delegations by the kernel
        # touch -a may fail if the file has been opened by another user than SYS_USER
        set +e
        do_as "$SYS_USER" find "$LOG_DIR/db" -name slow-queries.log \
            -user "$DB_USER" -delete
        do_as ${SYS_USER} touch -a ${MYSQL_LOG}
        set -e
    fi
    admin_cron || true

    foreach_daemon reload

    user_cron || true
}

function on_consoleenabled() {
    return 0;
}