Personal tools
You are here: Home Support Documentation OpenPKG x108.html
Document Actions

x108.html

Run Control

Each package may have a run control file that is used to:

  • Start, Stop, Restart, and reload the package.

  • Get the status of the package (running, not configured, ...).

  • Set the environment required by the package.

  • Run monthly, weekly, daily, hourly, and quarterly (15 minutes) cron jobs.

Run control under OpenPKG is very similar to the SYSV style scripts with a little FreeBSD thrown in for good measure. Each package may have a %{l_prefix}/etc/rc.d/rc.$packagename file which is a plain ascii file with sections to handle the various functions (start, stop, status, environment, %{l_prefix}/etc/rc.conf file. All run control is done by the %%l_prefix}/etc/rc script.


    %{l_prefix}/etc/rc ($package|all) command [command..]

Where command may be env, stop, start, restart, reload, status, hourly, daily, weekly, etc.

The apache run control file is probably a good example with all the sections:


#!/home/csoft/freebsd48/lib/openpkg/bash /home/csoft/freebsd48/etc/rc
##
##  rc.apache -- Run-Commands
##

%config
    apache_enable="$openpkg_rc_def"
    apache_log_files="/home/csoft/freebsd48/var/apache/log/access.log"
    apache_log_prolog="true"
    apache_log_epilog="true"
    apache_log_numfiles="10"
    apache_log_minsize="1M"
    apache_log_complevel="9"
    apache_err_files="/home/csoft/freebsd48/var/apache/log/error.log"
    apache_err_prolog="true"
    apache_err_epilog="true"
    apache_err_numfiles="10"
    apache_err_minsize="1M"
    apache_err_complevel="9"

%status -u root -o
    apache_usable="no"
    apache_active="no"
    /home/csoft/freebsd48/sbin/apachectl configtest 2>/dev/null && apache_usable="yes"
    ( eval `grep "^PIDFILE=" /home/csoft/freebsd48/sbin/apachectl`
      [ ".$PIDFILE" != . -a -f "$PIDFILE" ] && kill -0 `cat $PIDFILE`
    ) && apache_active="yes"
    echo "apache_enable=\"$apache_enable\""
    echo "apache_usable=\"$apache_usable\""
    echo "apache_active=\"$apache_active\""

%start -u root
    rcService apache enable yes || exit 0
    rcService apache active yes && exit 0
    /home/csoft/freebsd48/sbin/apachectl start

%stop -u root
    rcService apache enable yes || exit 0
    rcService apache active no  && exit 0
    /home/csoft/freebsd48/sbin/apachectl stop
    sleep 2

%restart -u root
    rcService apache enable yes || exit 0
    rcService apache active no  && exit 0
    /home/csoft/freebsd48/sbin/apachectl restart

%daily -u root
    rcService apache enable yes || exit 0

    if [ ".$apache_log_files" != . ]; then
        #   rotate logfile
        shtool rotate -f \
            -n ${apache_log_numfiles} -s ${apache_log_minsize} -d \
            -z ${apache_log_complevel} -m 644 -o root -g csoftmgr \
            -P "${apache_log_prolog}" \
            -E "${apache_log_epilog} && rc apache restart" \
            $apache_log_files
    fi

    if [ ".$apache_err_files" != . ]; then
        #   rotate errfile
        shtool rotate -f \
            -n ${apache_err_numfiles} -s ${apache_err_minsize} -d \
            -z ${apache_err_complevel} -m 644 -o root -g csoftmgr \
            -P "${apache_err_prolog}" \
            -E "${apache_err_epilog} && rc apache restart" \
            $apache_err_files
    fi



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: