Your IP : 216.73.216.21


Current Path : /pkg/zweb/1.0/bin/
Upload File :
Current File : //pkg/zweb/1.0/bin/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

https://nalibali.org/post-sitemap.xml 2026-11-20T09:00:00+00:00 https://nalibali.org/page-sitemap.xml 2026-11-18T09:24:11+00:00 https://nalibali.org/stories-sitemap.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/stories-sitemap2.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/audio_stories-sitemap.xml 2026-03-27T06:53:13+00:00 https://nalibali.org/story_cards-sitemap.xml 2025-06-06T10:27:48+00:00 https://nalibali.org/story_seeds-sitemap.xml 2025-05-19T07:35:43+00:00 https://nalibali.org/rhymes-sitemap.xml 2025-06-17T07:43:10+00:00 https://nalibali.org/activity_sheets-sitemap.xml 2025-05-16T09:16:43+00:00 https://nalibali.org/printables-sitemap.xml 2025-05-16T09:28:40+00:00 https://nalibali.org/posters_bookmarks-sitemap.xml 2025-05-16T10:20:22+00:00 https://nalibali.org/team_member-sitemap.xml 2025-05-28T09:40:43+00:00 https://nalibali.org/video_stories-sitemap.xml 2025-06-23T08:48:28+00:00 https://nalibali.org/guides-sitemap.xml 2025-06-17T09:38:41+00:00 https://nalibali.org/story_supplements-sitemap.xml 2025-09-16T12:22:20+00:00 https://nalibali.org/vacancies-sitemap.xml 2026-09-17T07:05:01+00:00 https://nalibali.org/category-sitemap.xml 2026-11-20T09:00:00+00:00 https://nalibali.org/post_tag-sitemap.xml 2026-11-06T00:00:00+00:00 https://nalibali.org/test-sitemap.xml 2025-06-13T09:36:28+00:00 https://nalibali.org/story_categories-sitemap.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/activity_sheets_categories-sitemap.xml 2025-05-16T09:16:43+00:00 https://nalibali.org/printables_categories-sitemap.xml 2025-05-16T09:28:40+00:00 https://nalibali.org/posters_bookmarks_categories-sitemap.xml 2025-05-16T10:20:22+00:00 https://nalibali.org/single_audio-sitemap.xml 2026-03-27T06:53:13+00:00 https://nalibali.org/rhyme_categories-sitemap.xml 2025-06-17T07:43:10+00:00 https://nalibali.org/guide_categories-sitemap.xml 2025-06-17T09:38:41+00:00 https://nalibali.org/author-sitemap.xml 2026-01-22T07:26:07+00:00