| Current Path : /cmd/ |
| Current File : //cmd/zweb-php-ctl.old |
#!/bin/bash
# zweb version number
version='1.0'
user=$(pwd | cut -d '/' -f4)
web="/srv/web/$user"
conf="$web/etc/php"
svc="/svc/$user-php"
snooze=10
if [ ! -L $svc -o ! -d $conf ]; then
echo "error: $svc error"
touch $svc/down
exit
fi
echo '----------------------------'
echo "notice: starting php control"
start='-u'
reload='-2'
restart='-t'
stop='-d'
if svup /svc/$user-php; then
echo "notice: php service is up"
else
echo "notice: php service is down"
fi
while true; do
cd $conf/ctl
for action in start reload restart stop; do
if [ -f $action ]; then
echo "action: requested $action"
if svup /svc/$user-php; then
if [ $action == 'start' ]; then
echo "notice: php service is up, so will reload"
action='reload'
fi
else
echo "notice: php service is down, so will start"
if [ $action == 'reload' -o $action == 'restart' ]; then
action='start'
fi
fi
if [ $action != 'stop' ]; then
if [ -f version.value ]; then
php_version=$(head -1 version.value)
if ! echo "$php_version" | grep -qE "^[1-9]{1}\.[0-9]{1,2}\.[0-9]{1,2}$"; then
echo "config: invalid version in version.value, using default"
version=$(basename $(readlink /pkg/php/default));
echo "config: using version $php_version"
echo $php_version > version.value
echo "config: will trigger restart"
action='restart'
fi
else
php_version=$(basename $(readlink /pkg/php/default));
echo "config: no version specified, using default $php_version"
echo $php_version > version.value
echo "config: will trigger restart"
action='restart'
fi
echo "config: version is $php_version"
if [ ! -d /pkg/php/$php_version ]; then
echo "config: version $php_version unavailable"
continue # exit 'actions' loop
cp $conf/version.value .
fi
echo $php_version > $conf/version.value
php_version_series=$(echo $php_version | cut -d '.' -f1,2)
echo "config: version_series is $php_version_series"
for ext in conf ini; do
echo "config: adding core php.$ext"
cp /pkg/zweb/$version/etc/php/$php_version_series/php.$ext $conf
done
if [ -f redis.module ]; then
echo "config: redis module enabled in php.ini"
cat /pkg/zweb/$version/etc/php/$php_version_series/redis.ini >> $conf/php.ini
touch $conf/redis.module
else
rm -f $conf/redis.module
fi
session=''
if [ -f session.value ]; then
if head -1 session.value | grep -qE '^redis[[:space:]]{0,}$'; then
if [ -f redis.module ]; then
echo "config: enabling redis sessions in php.conf"
cat /pkg/zweb/$version/etc/php/$php_version_series/session.redis >> $conf/php.conf
echo redis > $conf/session.value
else
echo "config: cannot enable redis sessions; redis module not enabled"
session='default'
fi
elif head -1 session.value | grep -qE '^file[[:space:]]{0,}$'; then
echo "config: enabling file sessions in php.conf"
cat /pkg/zweb/$version/etc/php/$php_version_series/session.file >> $conf/php.conf
echo file > $conf/session.value
fi
else
session='default'
fi
if [ "$session" == 'default' ]; then
echo "config: enabling default file sessions in php.conf"
cat /pkg/zweb/$version/etc/php/$php_version_series/session.file >> $conf/php.conf
echo file > $conf/session.value
fi
if [ -f opcache.module ]; then
echo "config: opcache module enabled in php.ini"
cat /pkg/zweb/$version/etc/php/$php_version_series/opcache.ini >> $conf/php.ini
# are the next 2 lines necessary?
mkdir -p $web/tmp/php/opcache
chown $user:$user $web/tmp/php/opcache
# record that opcache was started
touch $conf/opcache.module
elif [ -f $conf/opcache.module -a -d $web/tmp/php/opcache ]; then
if cd $web/tmp/php; then
echo "config: opcache module disabled in php.ini"
echo "notice: clearing opcache"
if rm -rf opcache; then
mkdir opcache
chown $user:$user opcache
rm -f $conf/opcache.module
fi
fi
else
rm -f $conf/opcache.module
fi
sed -i "s/_USER_/$user/g;s/_VERSION_/$php_version/g" $conf/php.conf
sed -i "s/_USER_/$user/g;s/_VERSION_/$php_version/g" $conf/php.ini
fi
/cmd/svc ${!action} /svc/$user-php
echo "action: executed $action"
fi
done
# clean-up
rm -f start reload restart stop
sleep $snooze
done