ПРОЕКТЫ 


  АРХИВ 


Apache-Talk @lexa.ru 

Inet-Admins @info.east.ru 

Filmscanners @halftone.co.uk 

Security-alerts @yandex-team.ru 

nginx-ru @sysoev.ru 


  СТАТЬИ 


  ПЕРСОНАЛЬНОЕ 


  ПРОГРАММЫ 



ПИШИТЕ
ПИСЬМА












     АРХИВ :: nginx-ru
Nginx-ru mailing list archive (nginx-ru@sysoev.ru)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

www/nginx-devel: поддержка профилей (Was: директивы в командной строке)



On Wed, Jun 25, 2008 at 09:27:48PM +0400, Igor Sysoev wrote:
> Я сделал возможность указывать глобальные директивы в командной строке,
> например,
> 
> nginx -d 'pid /var/run/nginx.pid; worker_processes 2;'

После появления PR ports/124940 и реализации Игорем '-d ...' в лучших
традициях opensource предлагается проверенная технология поддержки профилей.

Special thanks to:      Andrej Zverev <az@xxxxxxxxxxx>

Для тестирования патч patch.d_param1 добавить в каталог files порта 
www/nginx-devel.

Пример конфигурации из /etc/rc.conf.
nginx_enable="YES"
nginx_profiles="one two"
nginx_one_configfile="/usr/local/etc/nginx.one/nginx.conf"
nginx_two_configfile="/usr/local/etc/nginx.two/nginx.conf"

Просьба тестировать.

Index: ports/www/nginx-devel/Makefile
===================================================================
RCS file: /home/pcvs/ports/www/nginx-devel/Makefile,v
retrieving revision 1.149
diff -u -r1.149 Makefile
--- ports/www/nginx-devel/Makefile      23 Jun 2008 11:13:33 -0000      1.149
+++ ports/www/nginx-devel/Makefile      26 Jun 2008 08:06:39 -0000
@@ -7,6 +7,7 @@
 
 PORTNAME=      nginx
 PORTVERSION=   0.7.3
+PORTREVISION=  1
 CATEGORIES=    www
 MASTER_SITES=  http://sysoev.ru/nginx/
 MASTER_SITES+= ${MASTER_SITE_LOCAL}
@@ -45,6 +46,8 @@
 
 CONFLICTS?=    nginx-0.5.*
 USE_RC_SUBR=   nginx.sh
+SUB_LIST+=     RC_SUBR_SUFFIX=${RC_SUBR_SUFFIX} WWWOWN=${WWWOWN}
+
 HAS_CONFIGURE= yes
 CONFIGURE_ARGS+=--prefix=${ETCDIR}                 --with-cc-opt="-I ${LOCALBASE}/include" Index: ports/www/nginx-devel/files/nginx.sh.in
===================================================================
RCS file: /home/pcvs/ports/www/nginx-devel/files/nginx.sh.in,v
retrieving revision 1.3
diff -u -r1.3 nginx.sh.in
--- ports/www/nginx-devel/files/nginx.sh.in     18 Jun 2007 07:13:27 -0000      
1.3
+++ ports/www/nginx-devel/files/nginx.sh.in     26 Jun 2008 08:06:39 -0000
@@ -1,44 +1,109 @@
 #!/bin/sh
-# $FreeBSD: ports/www/nginx-devel/files/nginx.sh.in,v 1.3 2007/06/18 07:13:27 
osa Exp $
+#
+# $FreeBSD$
+#
 
 # PROVIDE: nginx
-# REQUIRE: DAEMON
-# BEFORE: LOGIN
+# REQUIRE: LOGIN cleanvar
 # KEYWORD: shutdown
 
-# Define these nginx_* variables in one of these files:
-#       /etc/rc.conf
-#       /etc/rc.conf.local
-#       /etc/rc.conf.d/nginx
 #
-# DO NOT CHANGE THESE DEFAULT VALUES HERE
-#
-nginx_enable=${nginx_enable-"NO"}
-nginx_flags=${nginx_flags-""}
-nginx_pidfile=${nginx_pidfile-"/var/run/nginx.pid"}
+# Add the following lines to /etc/rc.conf to enable nginx:
+# nginx_enable (bool):         Set to "NO" by default.
+#                              Set it to "YES" to enable nginx
+# nginx_profiles (str):                Set to "" by default.
+#                              Define your profiles here.
+# nginxlimits_enable (bool):   Set to "NO" by default.
+#                              Set it to yes to run `limits $limits_args`
+#                              just before nginx starts.
+# nginx_flags (str):           Set to "" by default.
+#                              Extra flags passed to start command.
+# nginxlimits_args (str):      Default to "-e -U %%WWWOWN%%"
+#                              Arguments of pre-start limits run.
 
 . %%RC_SUBR%%
 
 name="nginx"
 rcvar=`set_rcvar`
+
+start_precmd="nginx_precmd"
+restart_precmd="nginx_checkconfig"
+reload_precmd="nginx_checkconfig"
+reload_cmd="nginx_reload"
+configtest_cmd="nginx_checkconfig"
 command="%%PREFIX%%/sbin/nginx"
+_pidprefix="/var/run/nginx"
+pidfile="${_pidprefix}.pid"
+required_files=%%PREFIX%%/etc/nginx/nginx.conf
+
+[ -z "$nginx_enable" ]       && nginx_enable="NO"
+[ -z "$nginx_profiles" ]     && nginx_profiles=""
+[ -z "$nginx_flags" ]        && nginx_flags=""
+[ -z "$nginxlimits_enable" ] && nginxlimits_enable="NO"
+[ -z "$nginxlimits_args" ]   && nginxlimits_args="-e -U %%WWWOWN%%"
 
 load_rc_config $name
 
-pidfile="${nginx_pidfile}"
-
-extra_commands="configtest reload"
-
-configtest_cmd="configtest_cmd"
-configtest_cmd()  {
-       echo "Configuration syntax test for ${name}."
-       if ${command} ${nginx_flags} -t; then
-               :
+if [ -n "$2" ]; then
+       profile="$2"
+       if [ "x${nginx_profiles}" != "x" ]; then
+               pidfile="${_pidprefix}.${profile}.pid"
+               eval nginx_configfile="\${nginx_${profile}_configfile:-}"
+               if [ "x${nginx_configfile}" = "x" ]; then
+                       echo "You must define a configuration file 
(nginx_${profile}_configfile)"
+                       exit 1
+               fi
+               required_files="${nginx_configfile}"
+               eval nginx_enable="\${nginx_${profile}_enable:-${nginx_enable}}"
+               eval nginx_flags="\${nginx_${profile}_flags:-${nginx_flags}}"
+               eval 
nginxlimits_enable="\${nginxlimits_${profile}_enable:-${nginxlimits_enable}}"
+               eval 
nginxlimits_args="\${nginxlimits_${profile}_args:-${nginxlimits_args}}"
+               nginx_flags="-c ${nginx_configfile} -d \"pid ${pidfile};\" 
${nginx_flags}"
        else
-               err 8 "FATAL: bad config for ${name}"
+               echo "$0: extra argument ignored"
+       fi
+else
+       if [ "x${nginx_profiles}" != "x" -a "x$1" != "x" ]; then
+               for profile in ${nginx_profiles}; do
+                       echo "===> nginx profile: ${profile}"
+                       %%PREFIX%%/etc/rc.d/nginx%%RC_SUBR_SUFFIX%% $1 
${profile}
+                       retcode="$?"
+                       if [ "0${retcode}" -ne 0 ]; then
+                               failed="${profile} (${retcode}) ${failed:-}"
+                       else
+                               success="${profile} ${success:-}"
+                       fi
+               done
+               exit 0
        fi
+fi
+
+nginx_requirepidfile()
+{
+       if [ ! "0`check_pidfile ${pidfile} ${command}`" -gt 1 ]; then
+               echo "${name} not running? (check $pidfile)."
+               exit 1
+       fi
+}
+
+nginx_checkconfig()
+{
+       echo "Performing sanity check on nginx configuration:"
+       eval ${command} ${nginx_flags} -t
 }
 
-start_cmd="echo \"Starting ${name}.\"; /usr/bin/limits -U www ${command} 
${nginx_flags}"
+nginx_precmd() 
+{
+       nginx_checkconfig
+
+       if checkyesno nginxlimits_enable
+       then
+               eval `/usr/bin/limits ${nginxlimits_args}` 2>/dev/null
+       else
+               return 0
+        fi
+
+}
 
+extra_commands="reload configtest"
 run_rc_command "$1"

-- 
Sergey A. Osokin,
System Engineer,
Macomnet, Internet Dept.
tel: +7 (495) 796-9079
fax: +7 (495) 796-9067



 




Copyright © Lexa Software, 1996-2009.