File: //proc/self/root/bin/backuply
#!/bin/bash
# Assume we run without the wrapper by default.
USE_CGROUP_WRAPPER=false
# Check if the --enduser_backup flag is passed.
for arg in "$@"; do
# If it is, check if either cgroup v1 or v2 is available.
if [[ "$arg" == "--enduser_backup" ]]; then
if [[ (-f /sys/fs/cgroup/cgroup.controllers || ( -d /sys/fs/cgroup/cpu && -d /sys/fs/cgroup/memory && -d /sys/fs/cgroup/blkio )) && -f /var/backuply/conf/resource_limits_enabled ]]; then
USE_CGROUP_WRAPPER=true
fi
# Since we found the flag, we can stop looping.
break
fi
done
# Use the cgroup wrapper. The wrapper itself will handle v1/v2 differences.
if [[ "$USE_CGROUP_WRAPPER" == true ]]; then
/usr/local/backuply/bin/backuply-cgroup /usr/local/backuply/bin/php /usr/local/backuply/cli.php "$@"
# Run the command directly without the wrapper.
else
/usr/local/backuply/bin/php /usr/local/backuply/cli.php "$@"
fi