summaryrefslogblamecommitdiffstats
path: root/satellit_installer/static_files/patch_lighttpd_phpchildren
blob: a8e44e543b0bab0250783f415af678f0c959d36b (plain) (tree)
1
2
3
4
5
6
7
8
9
         

                                                                            
                                                                  




                                                                                                 
 






                                                                                                           
    
                                                                                          



              
#!/bin/sh

# Could be written in one line, but for better editing when values change...
MEM=$(grep ^MemTotal /proc/meminfo | awk '{print $2}') # RAM in KB
MEM=$(( MEM / 1024 / 4 ))                             # to MB, and assess a fourth of RAM for PHP
CHILDREN=$(( MEM / 16 ))                              # assume 16 MB per child
# min 16, no more than 128 (inverse logic to handle NaN)
[ "$CHILDREN" -ge 16 ] || CHILDREN=16
[ "$CHILDREN" -le 128 ] || CHILDREN=128

## Use ?? in case the ordering changes one day
file=$(echo /etc/lighttpd/conf-enabled/??-fastcgi-php.conf)
if [ -f "$file" ]; then
	sed -i 's/"PHP_FCGI_CHILDREN.*$/"PHP_FCGI_CHILDREN" => "'$CHILDREN'",/' "$file"
	if ! grep -qF '"PHP_FCGI_CHILDREN" => "'$CHILDREN'"' "$file"; then
		echo "WARNING: Cannot adjust php cgildren count for fastcgi -- line not found in $file" >&2
	fi
else
	echo "WARNING: Cannot adjust php children count for fastcgi -- file not found" >&2
	exit 1
fi
exit 0