| Current Path : /var.old/run/sv/w4w-panel/ |
| Current File : //var.old/run/sv/w4w-panel/run |
#!/bin/ash
# redirect all stderr output to stdout for logging
exec 2>&1
RUN_DIR=$(pwd)
user='w4w'
home="/srv/web/$user"
abort() {
error="$1"
echo "error: $error"
touch $RUN_DIR/down
echo "warn: service halted"
exit 1
}
if ! cd "$home" > /dev/null 2>&1; then
abort "cannot cd $home"
fi
if [ ! -f etc/panel/version ]; then
abort "missing $home/etc/panel/version"
fi
php_ver=$(head -n 1 etc/panel/version)
php_base="/pkg/php/$php_ver"
# where is php-fpm installed?
php_fpm=''
for d in bin sbin; do
php_fpm_test="$php_base/$d/php-fpm"
if [ -x $php_fpm_test ]; then
php_fpm="$php_fpm_test"
break
fi
done
if [ -z "$php_fpm" ]; then
abort 'missing {bin,sbin}/php-fpm'
fi
if [ ! -f $php_base/etc/php.ini.base ]; then
abort "no default php.ini.base for version $php"
fi
php_ini='etc/panel/php.ini'
if [ ! -f $php_ini ]; then
cp $php_base/etc/php.ini.base $php_ini
fi
php_conf='etc/panel/php.conf'
if [ ! -f $php_conf ]; then
abort "missing $php_conf"
fi
log_php="$home/log/php"
mkdir -p $log_php
touch $log_php/php.log
chown $user:$user $log_php/php.log
# prepare PHP tmp dir
temp_dir="/srv/web/$user/tmp/php"
mkdir -p $temp_dir
chown "$user:$user" "$temp_dir"
# ensure the user is able to create the socket
chown $user:$user $home/svc/php
# clear possible opcache cache, to avoid broken starts
rm -rf /srv/web/$user/tmp/php/opcache/*
echo "starting PHP $php_ver"
# PHP_INI_SCAN_DIR: do NOT scan for conf and ini files
# --no-php-ini: start with no conf and ini
# -c only load specified ini
# -y only load specified conf
# -F run in foreground
PHP_INI_SCAN_DIR="" \
exec "$php_fpm" \
-c "$home/$php_ini" \
-y "$home/$php_conf" \
-F