Edgewall Software

Changes between Version 17 and Version 18 of TracNginxRecipe


Ignore:
Timestamp:
Mar 11, 2012, 11:30:07 PM (12 years ago)
Author:
sandel@…
Comment:

FreeBSD rc.d startup script was added

Legend:

Unmodified
Added
Removed
Modified
  • TracNginxRecipe

    v17 v18  
    256256}}}
    257257
     258----
     259
     260Startup '''rc.d''' script for '''FreeBSD''' that allows you to run StandAlone server for '''multiple Trac Projects''' behind Nginx with '''ngx_http_proxy_module''' ''(proxy_pass)'' module.\\
     261This script better then default FreeBSD rc.d script because it’s smarter and supports multiple Trac Projects.\\
     262Also it supports '''authentication for each project separately''' with Trac basic authentication!
     263
     264`/usr/local/etc/rc.d/trac`
     265{{{
     266#!/bin/sh
     267#
     268# Trac (http://trac.edgewall.org/) startup rc.d
     269#
     270# (c) 2012 Stanislav Rudenko, sandel{at}ukr.net
     271#  Thanks to Alexey Tsvetnov, vorakl{at}fbsd.kiev.ua
     272#   last update 11.03.12
     273
     274# PROVIDE: tracd
     275# REQUIRE: LOGIN
     276# KEYWORD: shutdown
     277
     278#
     279# Add the following line to /etc/rc.conf to enable trac:
     280#  trac_enable="YES"
     281#
     282# and optional:
     283#  trac_data="/usr/local/www/trac"
     284#  trac_config="/usr/local/etc/trac.conf"
     285#  trac_user="trac"
     286#  trac_group="trac"
     287#  trac_port="8000"
     288#  trac_host="127.0.0.1"
     289#  trac_pidfile="/var/run/trac/trac.pid"
     290#
     291# You _MUST_ create config file --> /usr/local/etc/trac.conf
     292# and add the following lines:
     293#
     294#  DIR_PROJECT_1="/usr/local/www/trac/myproj"
     295#  NAMEDIR_PROJECT_1="myproj"
     296#  PATH_PASSFILE_1="/usr/local/www/trac/.htpasswd_myproj"
     297#  NAME_REALM_1="My Project"
     298#
     299# (also you can increment variables to use multiply projects)
     300# (for example DIR_PROJECT_2,...,NAME_REALM_2 etc...)
     301#
     302
     303. "/etc/rc.subr"
     304
     305name="trac"
     306rcvar=`set_rcvar`
     307load_rc_config $name
     308
     309# Set some defaults
     310trac_enable=${trac_enable:-"NO"}
     311trac_data=${trac_data:-"/usr/local/www/trac"}
     312trac_config=${trac_config:-"/usr/local/etc/trac.conf"}
     313trac_user=${trac_user:-"trac"}
     314trac_group=${trac_group:-"trac"}
     315trac_port=${trac_port:-"8000"}
     316trac_host=${trac_host:-"127.0.0.1"}
     317trac_pidfile=${trac_pidfile:-"/var/run/trac/trac.pid"}
     318
     319start_cmd="trac_start"
     320start_precmd="trac_precmd"
     321
     322required_files="/usr/local/bin/sudo"
     323
     324pidfile=${trac_pidfile}
     325
     326command="/usr/local/bin/tracd"
     327command_interpreter="/usr/local/bin/python2.5"
     328
     329trac_precmd()
     330{
     331        if [ ! -s "${trac_config}" ]
     332         then
     333          trac_configexample
     334          return 1
     335        fi
     336
     337        . "${trac_config}"
     338
     339
     340        piddir=$(/usr/bin/dirname "${trac_pidfile}")
     341        if [ ! -d ${piddir} ]
     342         then
     343          /bin/mkdir -p "${piddir}"
     344          /usr/sbin/chown ${trac_user}:${trac_group} "${piddir}"
     345        fi
     346
     347        /usr/local/bin/sudo -u ${trac_user} /bin/sh -c "if [ -d \"${piddir}\" -a -w \"${piddir}\" ];then return 0;else return 1;fi"
     348        if [ $? -ne 0 ]
     349         then
     350         echo "Can't write .pid file to \"${piddir}\"!!! Change directory permissions!"
     351         return 1
     352        fi
     353
     354        if [ -s "${trac_pidfile}" ]
     355         then
     356          /bin/ps -axp "$(/bin/cat ${trac_pidfile})" >/dev/null 2>&1
     357          if [ $? -eq 0 ]
     358           then
     359            echo "trac already running! (check ${trac_pidfile})"
     360            return 1
     361          fi
     362          /bin/rm -f "${trac_pidfile}"
     363         else
     364          trpid=$(/usr/bin/pgrep "/usr/local/bin/tracd")
     365          if [ -n "${trpid}" ]
     366           then
     367            echo "trac(${trpid}) already running, but can't find PID file!!!"
     368            return 1
     369          fi
     370        fi
     371
     372
     373        i=0
     374        while :
     375         do
     376          i=$(( $i + 1 ))
     377          [ -z "$(eval echo "\${DIR_PROJECT_${i}}")" ] && break
     378
     379          NAMEDIR_PROJECT=$(eval echo "\${NAMEDIR_PROJECT_${i}}")
     380          PATH_PASSFILE=$(eval echo "\${PATH_PASSFILE_${i}}")
     381          NAME_REALM=$(eval echo "\${NAME_REALM_${i}}")
     382          DIR_PROJECT=$(eval echo "\${DIR_PROJECT_${i}}")
     383
     384          basicauth="${basicauth} --basic-auth=\"${NAMEDIR_PROJECT},${PATH_PASSFILE},${NAME_REALM}\""
     385          projects="${projects} \"${DIR_PROJECT}\""
     386        done
     387
     388        rc_flags="-d -p ${trac_port} -b ${trac_host} -e ${trac_data} --pidfile=${pidfile}${basicauth}${projects}"
     389}
     390
     391trac_start()
     392{
     393        /bin/echo -n "Starting ${name}"
     394
     395        eval /usr/local/bin/sudo -u ${trac_user} env PYTHON_EGG_CACHE=${trac_data}/.python-eggs ${command} ${rc_flags}
     396
     397        /bin/echo "."
     398}
     399
     400trac_configexample()
     401{
     402        echo ""
     403        echo "=========================================================="
     404        echo "You _MUST_ create config at /usr/local/etc/trac.conf"
     405        echo "and add the following lines:"
     406        echo ""
     407        echo "DIR_PROJECT_1=\"/usr/local/www/trac/myproj\""
     408        echo "NAMEDIR_PROJECT_1=\"myproj\""
     409        echo "PATH_PASSFILE_1=\"/usr/local/www/trac/.htpasswd_myproj\""
     410        echo "NAME_REALM_1=\"My Project\""
     411        echo "=========================================================="
     412        echo ""
     413}
     414
     415run_rc_command "$1"
     416
     417}}}
    258418
    259419== Todo ==
     
    265425
    266426----
    267 See also TracFastCgi#SimpleNginxConfiguration
     427See also TracFastCgi#SimpleNginxConfiguration1
     428          if [ $? -eq 0 ]
     429           then
     430            echo "trac already running! (check ${trac_pidfile})"
     431            return 1
     432          fi
     433          /bin/rm -f "${trac_pidfile}"
     434         else
     435          trpid=$(/usr/bin/pgrep "/usr/local/bin/tracd")
     436          if [ -n "${trpid}" ]
     437           then
     438            echo "trac(${trpid}) already running, but can't find PID file!!!"
     439            return 1
     440          fi
     441        fi
     442
     443
     444        i=0
     445        while :
     446         do
     447          i=$(( $i + 1 ))
     448          [ -z "$(eval echo "\${DIR_PROJECT_${i}}")" ]