diff options
author | mikka <miklos.martin@gmail.com> | 2012-09-02 15:43:20 +0200 |
---|---|---|
committer | mikka <miklos.martin@gmail.com> | 2012-09-02 15:43:20 +0200 |
commit | 3ef82a908a10979d9a4d14e0674902c85b14a99e (patch) | |
tree | 3c0793436e5e219d36136773f156cffae0e6ee49 /plugins/php-fpm | |
parent | 921d2f49ef01acce973980c0aa9c6ffbbd2fbd0b (diff) | |
download | zsh-3ef82a908a10979d9a4d14e0674902c85b14a99e.tar.gz zsh-3ef82a908a10979d9a4d14e0674902c85b14a99e.tar.bz2 zsh-3ef82a908a10979d9a4d14e0674902c85b14a99e.zip |
nginx and php-fpm plugins
Diffstat (limited to 'plugins/php-fpm')
-rw-r--r-- | plugins/php-fpm/php-fpm.plugin.zsh | 75 | ||||
-rw-r--r-- | plugins/php-fpm/templates/pool | 11 |
2 files changed, 86 insertions, 0 deletions
diff --git a/plugins/php-fpm/php-fpm.plugin.zsh b/plugins/php-fpm/php-fpm.plugin.zsh new file mode 100644 index 000000000..3c095058a --- /dev/null +++ b/plugins/php-fpm/php-fpm.plugin.zsh @@ -0,0 +1,75 @@ +: ${FPM_DIR:=/etc/php5/fpm} + +if [ $use_sudo -eq 1 ]; then + sudo="sudo" +else + sudo="" +fi + +_fpm_get_possible_pool_list () { + cat /etc/passwd | awk -F : '{print $1 }' +} + +_fpm_pool () { + compadd `_fpm_get_possible_pool_list` + +} + +pool () { + while getopts ":lh" option + do + case $option in + l ) ls $FPM_DIR/pool.d; return ;; + h ) _pool_usage; return ;; + * ) _pool_usage; return ;; # Default. + esac + done + + if [ ! $1 ]; then + user=$USER + else + user=$1 + fi + + _pool_generate $user +} +compdef _fpm_pool pool + +_pool_usage () { + echo "Usage: pool [options] [user]" + echo + echo "Options" + echo " -l Lists fpm pools" + echo " -h Get this help message" + return +} + +_pool_generate () { + user=$(cat /etc/passwd | grep $1 | awk -F : '{print $1 }') + + if [ ! $user ]; then + echo "User \033[31m$1\033[0m doesn't have an account on \033[33m$HOST\033[0m" + return + fi + + group=$(groups $user | cut -d " " -f 3) + + echo "Generating pool for \033[33m$user\033[0m user with \033[33m$group\033[0m group" + + user_id=$(cat /etc/passwd | grep $1 | awk -F : '{print $3 }') + pool_port=1$user_id + : ${FPM_POOL_TEMPLATE:=$ZSH/plugins/php-fpm/templates/pool} + + conf=$(sed -e 's/{user}/'$user'/g' -e 's/{group}/'$group'/g' -e 's/{pool_port}/'$pool_port'/g' $FPM_POOL_TEMPLATE ) + + echo $conf > $user.conf + $sudo mv $user.conf $FPM_DIR/pool.d/$user.conf + + if [ -e $FPM_DIR/pool.d/$user.conf ]; then + echo "Pool for \033[32m$user\033[0m user has been successfully created" + else + echo "An error occured during the creating of pool for \033[31m$user\033[0m user" + fi +} + +alias fpmr="$sudo service php5-fpm restart" diff --git a/plugins/php-fpm/templates/pool b/plugins/php-fpm/templates/pool new file mode 100644 index 000000000..80f6693e0 --- /dev/null +++ b/plugins/php-fpm/templates/pool @@ -0,0 +1,11 @@ +[{user}] +user = {user} +group = {group} + +listen = 127.0.0.1:{pool_port} + +pm = dynamic +pm.max_children = 10 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 +pm.max_requests = 100 |