#!/bin/sh # MT-Dispatch-rc.d 1.1 # # mt_dispatch_enable (bool): Set it to "YES" to enable mt-dispatch # Default is "NO". # other options: see below # # Copyright (c) 2007 Reed A. Cartwright, PhD # # Derived from fcgiphp rc.d script found on trac.lighttpd.net # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. . /etc/rc.subr name="mt_dispatch" rcvar=`set_rcvar` load_rc_config ${name} : ${mt_dispatch_enable="NO"} : ${mt_dispatch_children="2"} : ${mt_dispatch_max_requests="100"} : ${mt_dispatch_socket="/tmp/mt-dispatch.sock"} : ${mt_dispatch_addr="localhost"} : ${mt_dispatch_home="/usr/local/www/cgi-bin/mt"} : ${mt_dispatch_port="8003"} : ${mt_dispatch_bin_path="/usr/local/bin/mt-dispatch"} : ${mt_dispatch_user="www"} : ${mt_dispatch_group="www"} : ${mt_dispatch_pidfile="/var/run/www/mt-dispatch.pid"} : ${mt_dispatch_log="/var/log/mt-dispatch.log"} : ${mt_dispatch_env="SHELL PATH USER"} : ${mt_dispatch_perl5lib=""} pidfile="${mt_dispatch_pidfile}" procname="perl-fcgi-pm" command_args="/usr/local/bin/spawn-fcgi -f '${mt_dispatch_bin_path}' -u '${mt_dispatch_user}' -g '${mt_dispatch_group}' -C '${mt_dispatch_children}' -P '${pidfile}'" start_precmd=start_precmd stop_postcmd=stop_postcmd start_precmd() { # setup environment PERL_FCGI_MAX_REQUESTS="${mt_dispatch_max_requests}" PERL_FCGI_LOG="${mt_dispatch_log}" FCGI_WEB_SERVER_ADDRS="${mt_dispatch_addr}" perl5libs="${mt_dispatch_home}/lib:${mt_dispatch_home}/extlib" if [ -n "${mt_dispatch_perl5lib}" ]; then PERL5LIB="${perl5libs}:${mt_dispatch_perl5lib}" else PERL5LIB="${perl5libs}" fi MT_HOME="${mt_dispatch_home}" MT_CONFIG="${mt_dispatch_home}/mt-config.cgi" export PERL_FCGI_MAX_REQUESTS export PERL_FCGI_LOG export FCGI_WEB_SERVER_ADDRS export PERL5LIB export MT_HOME export MT_CONFIG # copy the allowed environment variables allowed_env="${mt_dispatch_env} PERL_FCGI_MAX_REQUESTS PERL_FCGI_LOG FCGI_WEB_SERVER_ADDRS PERL5LIB MT_HOME MT_CONFIG" E="" for i in $allowed_env; do eval "x=\$$i" E="$E $i=$x" done command="env - $E" #setup directories and files dir=${mt_dispatch_pidfile%/*} if [ ! -d ${dir} ]; then mkdir ${dir} chown ${mt_dispatch_user}:${mt_dispatch_group} ${dir} fi dir=${mt_dispatch_log%/*} if [ ! -d ${dir} ]; then mkdir ${dir} chown ${mt_dispatch_user}:${mt_dispatch_group} ${dir} fi if [ ! -e ${mt_dispatch_log} ]; then touch ${mt_dispatch_log} chown ${mt_dispatch_user}:${mt_dispatch_group} ${mt_dispatch_log} fi # setup command_args if [ -n "${mt_dispatch_socket}" ]; then command_args="${command_args} -s ${mt_dispatch_socket}" elif [ -n "${mt_dispatch_port}" ]; then command_args="${command_args} -p ${mt_dispatch_port}" else echo "socket or port must be specified!" exit fi } stop_postcmd() { rm -f ${pidfile} } run_rc_command "$1"