From: Dragan Dosen Date: Sun, 30 Mar 2008 18:57:34 +0000 (+0200) Subject: * dodana config skripta (slicno kao kod php4-cn za Debian sarge) X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=commitdiff_plain;h=de39535cd06585d6895fb78304d45c4f83d04273;p=php4-cn.git * dodana config skripta (slicno kao kod php4-cn za Debian sarge) * config i postinst skripta - preporucene vrijednosti za post_max_size i memory_limit postavke odredjuju se ovisno o kolicini memorije na posluzitelju. * u slucaju da ne postoji neka od php.ini datoteka, koristi se /usr/share/php4/php.ini-dist za kreiranje nove. * README.CARNet datoteka --- diff --git a/debian/README.CARNet b/debian/README.CARNet index b21f8f0..7d637ae 100644 --- a/debian/README.CARNet +++ b/debian/README.CARNet @@ -15,16 +15,23 @@ server, cinite to u datoteci: /etc/php4/apache2/php.ini -Specificne postavke koje php4-cn paket automatski postavlja u -navedenoj datoteci: +Specificne postavke koje php4-cn paket postavlja u navedenoj +datoteci: upload_max_filesize = 256M - post_max_size = 256MB - memory_limit = 256M + post_max_size = + memory_limit = -Konfiguracije za pojedine PHP4 dodatke (extensions) nalaze se -unutar direktorija /etc/php4/conf.d/. Preporuka je da NE dirate -i da NE brisete iste, osim ako znate sto cinite. +post_max_size i memory_limit postavke se odredjuju ovisno o +kolicini memorije na posluzitelju, tocnije: + + * manje od 512MB => ogranicenje 16MB, + * 512-1024MB => ogranicenje 32MB, + * vise od 1024MB => ogranicenje 64MB. + +U slucaju da na posluzitelju postoji PHP4 konfiguracija koja +se razlikuje od navedene, bit cete upitani zelite li zadrzati +trenutne postavke ili aktivirati preporucene. Nakon sto prepravite PHP4 konfiguraciju, potrebno je obaviti restart Apache2 web servera: @@ -46,4 +53,4 @@ stranice pisane u PHP-u, preporuca se da NE brisete i da ne uredjujete navedene datoteke, osim ako znate sto cinite. - -- Dragan Dosen Sun, 27 Jan 2008 14:54:24 +0100 + -- Dragan Dosen Sun, 30 Mar 2008 20:03:30 +0200 diff --git a/debian/changelog b/debian/changelog index 9afb5b2..4bcc661 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,24 @@ +php4-cn (4:4.4.4-5) stable; urgency=medium + + * dodana config skripta: + + usporedba trenutno aktivnih PHP4 postavki s onima koje + preporuca CARNet (upload_max_filesize, post_max_size, + memory_limit) + + koristi se debconf - u slucaju da se postavke razlikuju, + korisnik odlucuje zeli li zadrzati trenutne postavke ili + aktivirati preporucene + * config i postinst skripta - preporucene vrijednosti za + post_max_size i memory_limit postavke odredjuju se ovisno o + kolicini memorije na posluzitelju. + * u slucaju da ne postoji neka od php.ini datoteka, koristi + se /usr/share/php4/php.ini-dist za kreiranje nove. + * podesavanje postavki (php.ini datoteka/e) odvija se samo kod + prve instalacije paketa ili u slucaju da se pokrene + * README.CARNet datoteka - opisano odredjivanje preporucene + vrijednosti za post_max_size i memory_limit postavke. + + -- Dragan Dosen Sun, 30 Mar 2008 20:03:30 +0200 + php4-cn (4:4.4.4-4) stable; urgency=low * control datoteka - version epoch. diff --git a/debian/config b/debian/config new file mode 100755 index 0000000..6140a86 --- /dev/null +++ b/debian/config @@ -0,0 +1,105 @@ +#!/bin/sh + +set -e + +# Load debconf +. /usr/share/debconf/confmodule + +if [ "$1" != reconfigure ]; then + + php4_done=1 + + for SAPI in apache2 cli; do + db_fget php4-cn/${SAPI} seen + if [ "$RET" != "true" ]; then + php4_done=0 + break + fi + done + + test $php4_done -eq 1 && exit 0 +fi + +PHP4DIR="/etc/php4" + +# phpmemlimit () +# +# Calculate memory size for PHP memory_limit option. +# +phpmemlimit () { + + local memtotal memlimit + memtotal=`awk 'tolower($1) == "memtotal:" { printf("%i", $2/1024); }' /proc/meminfo` + + if [ $memtotal -lt 512 ]; then memlimit=16; fi + if [ $memtotal -ge 512 ]; then memlimit=32; fi + if [ $memtotal -gt 1024 ]; then memlimit=64; fi + + echo $memlimit +} + + +# Check for PHP4 SAPI configuration. +# +for SAPI in apache2 cli; do + + if [ ! -d "$PHP4DIR/$SAPI" ]; then + continue + fi + + ini_diff=0 + ini_file="$PHP4DIR/$SAPI/php.ini" + + phplimit="$(phpmemlimit)M" + + if [ -f "$ini_file" ]; then + + if egrep -q "^[[:space:]]*(upload_max_filesize|post_max_size|memory_limit)[[:space:]]*=" $ini_file; then + + upload_max_filesize=`awk '$1 == "upload_max_filesize" { print $3; exit(0) }' $ini_file` + post_max_size=`awk '$1 == "post_max_size" { print $3; exit(0) }' $ini_file` + memory_limit=`awk '$1 == "memory_limit" { print $3; exit(0) }' $ini_file` + + if [ "$upload_max_filesize" != "256M" ]; then ini_diff=1; fi + if [ "$post_max_size" != "$phplimit" ]; then ini_diff=1; fi + if [ "$memory_limit" != "$phplimit" ]; then ini_diff=1; fi + else + + ini_diff=1 + fi + else + + ini_diff=1 + fi + + if [ $ini_diff -eq 1 ]; then + + # Configurations are not the same - ask user what to do. + test -z "$upload_max_filesize" && upload_max_filesize="2M" + test -z "$post_max_size" && post_max_size="8M" + if [ "$SAPI" = "cli" ]; then + test -z "$memory_limit" && memory_limit="32M" + else + test -z "$memory_limit" && memory_limit="8M" + fi + + db_title php4-cn - konfiguracija za $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/') + db_subst php4-cn/${SAPI} ini_file "$ini_file" + + db_subst php4-cn/${SAPI} upload_max_filesize "$upload_max_filesize" + db_subst php4-cn/${SAPI} post_max_size "$post_max_size" + db_subst php4-cn/${SAPI} memory_limit "$memory_limit" + + db_subst php4-cn/${SAPI} new_phplimit "$phplimit" + + db_input critical php4-cn/${SAPI} || true + db_go || true + else + + db_set php4-cn/${SAPI} false || true + db_fset php4-cn/${SAPI} seen true + fi + +done + +exit 0 diff --git a/debian/postinst b/debian/postinst index ee98700..26a3e5f 100755 --- a/debian/postinst +++ b/debian/postinst @@ -20,6 +20,9 @@ case "$1" in esac +# Load debconf +. /usr/share/debconf/confmodule + # Include CARNet functions . /usr/share/carnet-tools/functions.sh @@ -32,19 +35,75 @@ PHP4CONFD="/etc/php4/conf.d" need_restart=0 +# phpmemlimit () +# +# Calculate memory size for PHP memory_limit option. +# +phpmemlimit () { + + local memtotal memlimit + memtotal=`awk 'tolower($1) == "memtotal:" { printf("%i", $2/1024); }' /proc/meminfo` + + if [ $memtotal -lt 512 ]; then memlimit=16; fi + if [ $memtotal -ge 512 ]; then memlimit=32; fi + if [ $memtotal -gt 1024 ]; then memlimit=64; fi + + echo $memlimit +} + + # Disable PHP5 module and enable Apache2 PHP4 module. # if [ -e /etc/apache2/apache2.conf ]; then - if [ -e "$A2MODEDIR/php5.load" ]; then - cp_echo "CN: Disabling PHP5 module for Apache2 web server" - a2dismod php5 >/dev/null || true - need_restart=1 + if [ -e "$A2MODEDIR/php5.load" ]; then + cp_echo "CN: Disabling PHP5 module for Apache2 web server" + a2dismod php5 >/dev/null || true + need_restart=1 + fi + if [ ! -e "$A2MODEDIR/php4.load" ] || [ ! -e "$A2MODEDIR/php4.conf" ]; then + cp_echo "CN: Enabling PHP4 module for Apache2 web server" + a2enmod php4 >/dev/null || true + need_restart=1 + fi +fi + + +# Check for PHP4 SAPI directories and configuration files. +# +for SAPI in apache2 cli; do + + if [ ! -d "$PHP4DIR/$SAPI" ]; then + cp_echo "CN: Creating configuration directory $PHP4DIR/$SAPI/" + mkdir -p $PHP4DIR/$SAPI/ fi - if [ ! -e "$A2MODEDIR/php4.load" ] || [ ! -e "$A2MODEDIR/php4.conf" ]; then - cp_echo "CN: Enabling PHP4 module for Apache2 web server" - a2enmod php4 >/dev/null || true + + ini_file="$PHP4DIR/$SAPI/php.ini" + + if [ ! -f "$ini_file" ]; then + + cp_echo "CN: Generating configuration file $ini_file" + + ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX` + if [ "$SAPI" = "cli" ]; then + if [ -f "/usr/share/php4/php.ini-dist.cli" ]; then + cat /usr/share/php4/php.ini-dist.cli > $ini_file_tmp + fi + else + if [ -f "/usr/share/php4/php.ini-dist" ]; then + cat /usr/share/php4/php.ini-dist > $ini_file_tmp + fi + fi + cp_mv $ini_file_tmp $ini_file need_restart=1 fi +done + + +# Check for /etc/php4/conf.d/ directory. +# +if [ ! -d "$PHP4CONFD" ]; then + cp_echo "CN: Creating configuration directory $PHP4CONFD" + mkdir -p $PHP4CONFD/ fi @@ -54,31 +113,22 @@ for php4ext in $EXTENSIONS; do php4ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php4ext\.so" - # Remove extension entry from /etc/php4/(apache|apache2|cgi|cli).ini + # Remove extension entry from /etc/php4/(apache2|cli).ini # configuration files. - for SAPI in apache apache2 cgi cli; do - - if [ -d "$PHP4DIR/$SAPI" ]; then + for SAPI in apache2 cli; do - ini_file="$PHP4DIR/$SAPI/php.ini" + ini_file="$PHP4DIR/$SAPI/php.ini" - if [ -f "$ini_file" ]; then + if [ -f "$ini_file" ]; then cp_echo "CN: Removing $php4ext extension from file $ini_file" cp_check_and_sed "$php4ext_re" \ "/$php4ext_re/d" \ "$ini_file" && need_restart=1 || true - fi fi done - # Check $PHP4CONFD directory. - if [ ! -d "$PHP4CONFD" ]; then - cp_echo "CN: Creating configuration directory $PHP4CONFD" - mkdir $PHP4CONFD - fi - # Check extension configuration in /etc/php4/conf.d/ directory. if [ ! -f "$PHP4CONFD/$php4ext.ini" ]; then @@ -113,61 +163,68 @@ done # Enable some PHP4 tweaks for Apache2 web server (/etc/php4/apache2/php.ini). # # * upload_max_filesize = 256M -# * post_max_size = 256M -# * memory_limit = 256M +# * post_max_size, memory_limit = depends on system memory, we are using +# phpmemlimit() function. # -for SAPI in apache apache2 cgi cli; do +for SAPI in apache2 cli; do if [ ! -d "$PHP4DIR/$SAPI" ]; then continue fi - ini_file="$PHP4DIR/$SAPI/php.ini" + db_get php4-cn/${SAPI} || true + if [ "$RET" = "true" ]; then + + ini_file="$PHP4DIR/$SAPI/php.ini" - cp_echo "CN: Checking and enabling some CARNet specific parameters in file $ini_file" + cp_echo "CN: Checking and enabling some specific parameters in file $ini_file" + + phplimit="$(phpmemlimit)M" - if [ -f "$ini_file" ]; then + if [ -f "$ini_file" ]; then - cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=[[:space:]]*2M" \ + cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=" \ 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \ "$ini_file" && need_restart=1 || true - cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=[[:space:]]*8M" \ - 's/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = 256M/' \ + cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=" \ + "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${phplimit}/" \ "$ini_file" && need_restart=1 || true - cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=[[:space:]]*8M" \ - 's/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = 256M/' \ + cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=" \ + "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${phplimit}/" \ "$ini_file" && need_restart=1 || true - fi - - ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX` - if [ -f "$ini_file" ]; then - cat $ini_file > $ini_file_tmp - fi + fi - if ! egrep -q "^[[:space:]]*(upload_max_filesize|post_max_size|memory_limit)[[:space:]]*=" $ini_file_tmp; then + ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX` + if [ -f "$ini_file" ]; then + cat $ini_file > $ini_file_tmp + fi - if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then - echo "upload_max_filesize = 256M" >> "$ini_file_tmp" - fi - if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then - echo "post_max_size = 256MB" >> "$ini_file_tmp" - fi - if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then - echo "memory_limit = 256M" >> "$ini_file_tmp" - fi - cp_mv "$ini_file_tmp" "$ini_file" - + if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then + echo "upload_max_filesize = 256M" >> "$ini_file_tmp" need_restart=1 - fi - - if [ -e "$ini_file_tmp" ]; then + fi + if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then + echo "post_max_size = ${phplimit}" >> "$ini_file_tmp" + need_restart=1 + fi + if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then + echo "memory_limit = ${phplimit}" >> "$ini_file_tmp" + need_restart=1 + fi + cp_mv "$ini_file_tmp" "$ini_file" + + if [ -e "$ini_file_tmp" ]; then rm -f "$ini_file_tmp" + fi fi done +db_stop || true + + # Restart Apache2 web server if needed. # if [ $need_restart -eq 1 ]; then diff --git a/debian/templates b/debian/templates new file mode 100644 index 0000000..f4889e4 --- /dev/null +++ b/debian/templates @@ -0,0 +1,32 @@ +Template: php4-cn/apache2 +Type: boolean +Description: Zelite li aktivirati preporucene PHP4 postavke za Apache2? + Provjerom trenutne PHP4 konfiguracije za Apache2 (konfiguracijska + datoteka ${ini_file}), ustanovljeno je da su sljedece postavke aktivne: + . + upload_max_filesize = ${upload_max_filesize} + post_max_size = ${post_max_size} + memory_limit = ${memory_limit} + + Preporucamo sljedece: + . + upload_max_filesize = 256M + post_max_size = ${new_phplimit} + memory_limit = ${new_phplimit} + +Template: php4-cn/cli +Type: boolean +Description: Zelite li aktivirati preporucene PHP4 postavke za CLI? + Provjerom trenutne PHP4 konfiguracije za CLI (PHP interpreter + za komandnu liniju, konfiguracijska datoteka ${ini_file}), + ustanovljeno je da su sljedece postavke aktivne: + . + upload_max_filesize = ${upload_max_filesize} + post_max_size = ${post_max_size} + memory_limit = ${memory_limit} + + Preporucamo sljedece: + . + upload_max_filesize = 256M + post_max_size = ${new_phplimit} + memory_limit = ${new_phplimit}