3ef82a908a10979d9a4d14e0674902c85b14a99e
- Author
- mikka <miklos.martin@gmail.com>
- Committer
- mikka <miklos.martin@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/nginx/nginx.plugin.zsh b/plugins/nginx/nginx.plugin.zsh
2new file mode 100644
3index 0000000000000000000000000000000000000000..6dd90c6d528898f01fbb80d3dfadcade87086179
4--- /dev/null
5+++ b/plugins/nginx/nginx.plugin.zsh
6@@ -0,0 +1,195 @@
7+: ${NGINX_DIR:=/etc/nginx}
8+: ${NGINX_VHOST_TEMPLATE:=$ZSH/plugins/nginx/templates/symfony2}
9+
10+if [ $use_sudo -eq 1 ]; then
11+ sudo="sudo"
12+else
13+ sudo=""
14+fi
15+
16+# nginx basic completition
17+
18+_nginx_get_en_command_list () {
19+ ls -a $NGINX_DIR/sites-available | awk '/^[a-z][a-z.-]+$/ { print $1 }'
20+}
21+
22+_nginx_get_dis_command_list () {
23+ ls -a $NGINX_DIR/sites-enabled | awk '/^[a-z][a-z.-]+$/ { print $1 }'
24+}
25+
26+_nginx_en () {
27+ compadd `_nginx_get_en_command_list`
28+}
29+
30+_nginx_dis () {
31+ compadd `_nginx_get_dis_command_list`
32+}
33+
34+# Enabling a site
35+en () {
36+ if [ ! $1 ]; then
37+ echo "\033[337;41m\nThe name of the vhost is required!\n\033[0m";
38+ return
39+ fi
40+
41+ if [ ! -e $NGINX_DIR/sites-available/$1 ]; then
42+ echo "\033[31m$1\033[0m doesn't exist";
43+ return
44+ fi
45+
46+ if [ ! -e $NGINX_DIR/sites-enabled/$1 ]; then
47+ $sudo ln -s $NGINX_DIR/sites-available/$1 $NGINX_DIR/sites-enabled/$1;
48+ if [ -e /etc/nginx/sites-enabled/$1 ]; then
49+ echo "\033[32m$1\033[0m successfully enabled";
50+ else
51+ echo "An error occured during the enabling of \033[31m$1\033[0m";
52+ fi
53+ else
54+ echo "\033[31m$1\033[0m is already enabled";
55+ fi
56+}
57+compdef _nginx_en en
58+
59+# Disabling a site
60+dis () {
61+ if [ ! $1 ]; then
62+ echo "\033[337;41m\nThe name of the vhost is required!\n\033[0m";
63+ return
64+ fi
65+
66+ if [ ! -e $NGINX_DIR/sites-enabled/$1 ]; then
67+ echo "\033[31m$1\033[0m doesn't exist";
68+ else
69+ $sudo rm -f $NGINX_DIR/sites-enabled/$1;
70+ if [ ! -e $NGINX_DIR/sites-enabled/$1 ]; then
71+ echo "\033[32m$1\033[0m successfully disabled";
72+ else
73+ echo "An error occured during the disabling of \033[31m$1\033[0m";
74+ fi
75+ fi
76+}
77+compdef _nginx_dis dis
78+
79+# Completition of vhost
80+_nginx_get_possible_vhost_list () {
81+ ls -a $HOME/www | awk '/^[^.][a-z0-9._]+$/ { print $1 }'
82+}
83+
84+_nginx_vhost () {
85+ compadd `_nginx_get_possible_vhost_list`
86+}
87+
88+# Parsing arguments
89+vhost () {
90+ user=$USER;
91+ template=$NGINX_VHOST_TEMPLATE
92+ tpl="non_existing_template"
93+ enable=1
94+ write_hosts=0
95+ args=""
96+
97+ while getopts ":lu:t:nwh" option
98+ do
99+ case $option in
100+ l ) ls $NGINX_DIR/sites-enabled; return ;;
101+ u ) user=$OPTARG; args="$args -u $OPTARG" ;;
102+ t ) tpl=$OPTARG; args="$args -t $OPTARG" ;;
103+ n ) enable=0; args="$args -n" ;;
104+ w ) write_hosts=1; args="$args -w" ;;
105+ h ) _vhost_usage; return ;;
106diff --git a/plugins/nginx/templates/plain_php b/plugins/nginx/templates/plain_php
107new file mode 100644
108index 0000000000000000000000000000000000000000..f7995f5d5ab822a9e7cbd49e0cbcd6733857e428
109--- /dev/null
110+++ b/plugins/nginx/templates/plain_php
111@@ -0,0 +1,27 @@
112+server {
113+ root /home/{user}/www/{vhost};
114+ index index.php;
115+
116+ server_name {vhost};
117+
118+ error_log /var/log/nginx/{vhost}.error.log;
119+ access_log /var/log/nginx/{vhost}.access.log;
120+
121+ location / {
122+ try_files $uri $uri/ $uri/index.php;
123+ }
124+
125+ location ~ \.php$ {
126+ include fastcgi_params;
127+ fastcgi_index index.php;
128+ fastcgi_pass 127.0.0.1:{pool_port};
129+ fastcgi_split_path_info ^(.+\.php)(/.*)$;
130+
131+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
132+ fastcgi_param HTTPS off;
133+ }
134+
135+ location ~ /\.ht {
136+ deny all;
137+ }
138+}
139diff --git a/plugins/nginx/templates/symfony2 b/plugins/nginx/templates/symfony2
140new file mode 100644
141index 0000000000000000000000000000000000000000..4d5754ca1a3d77f9967252b437de72f06586360d
142--- /dev/null
143+++ b/plugins/nginx/templates/symfony2
144@@ -0,0 +1,27 @@
145+server {
146+ root /home/{user}/www/{vhost}/web;
147+ index app_dev.php;
148+
149+ server_name {vhost};
150+ client_max_body_size 10M;
151+
152+ error_log /var/log/nginx/{vhost}.error.log;
153+ access_log /var/log/nginx/{vhost}.access.log;
154+
155+ location / {
156+ try_files $uri $uri/ /app_dev.php;
157+ }
158+
159+ # pass the PHP scripts to FastCGI server listening on 127.0.0.1:{pool_port}
160+ location ~ ^/(app|app_dev|check)\.php(/|$) {
161+ fastcgi_pass 127.0.0.1:{pool_port};
162+ fastcgi_split_path_info ^(.+\.php)(/.*)$;
163+ include fastcgi_params;
164+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
165+ fastcgi_param HTTPS off;
166+ }
167+
168+ location ~ /\.ht {
169+ deny all;
170+ }
171+}
172diff --git a/plugins/php-fpm/php-fpm.plugin.zsh b/plugins/php-fpm/php-fpm.plugin.zsh
173new file mode 100644
174index 0000000000000000000000000000000000000000..3c095058ac4321430fb0203516ceb095f199261f
175--- /dev/null
176+++ b/plugins/php-fpm/php-fpm.plugin.zsh
177@@ -0,0 +1,75 @@
178+: ${FPM_DIR:=/etc/php5/fpm}
179+
180+if [ $use_sudo -eq 1 ]; then
181+ sudo="sudo"
182+else
183+ sudo=""
184+fi
185+
186+_fpm_get_possible_pool_list () {
187+ cat /etc/passwd | awk -F : '{print $1 }'
188+}
189+
190+_fpm_pool () {
191+ compadd `_fpm_get_possible_pool_list`
192+
193+}
194+
195+pool () {
196+ while getopts ":lh" option
197+ do
198+ case $option in
199+ l ) ls $FPM_DIR/pool.d; return ;;
200+ h ) _pool_usage; return ;;
201+ * ) _pool_usage; return ;; # Default.
202+ esac
203+ done
204+
205+ if [ ! $1 ]; then
206+ user=$USER
207+ else
208+ user=$1
209+ fi
210+
211+ _pool_generate $user
212+}
213+compdef _fpm_pool pool
214+
215+_pool_usage () {
216+ echo "Usage: pool [options] [user]"
217+ echo
218+ echo "Options"
219+ echo " -l Lists fpm pools"
220+ echo " -h Get this help message"
221+ return
222+}
223+
224+_pool_generate () {
225+ user=$(cat /etc/passwd | grep $1 | awk -F : '{print $1 }')
226+
227+ if [ ! $user ]; then
228+ echo "User \033[31m$1\033[0m doesn't have an account on \033[33m$HOST\033[0m"
229+ return
230+ fi
231+
232+ group=$(groups $user | cut -d " " -f 3)
233+
234+ echo "Generating pool for \033[33m$user\033[0m user with \033[33m$group\033[0m group"
235+
236+ user_id=$(cat /etc/passwd | grep $1 | awk -F : '{print $3 }')
237+ pool_port=1$user_id
238+ : ${FPM_POOL_TEMPLATE:=$ZSH/plugins/php-fpm/templates/pool}
239+
240+ conf=$(sed -e 's/{user}/'$user'/g' -e 's/{group}/'$group'/g' -e 's/{pool_port}/'$pool_port'/g' $FPM_POOL_TEMPLATE )
241+
242+ echo $conf > $user.conf
243+ $sudo mv $user.conf $FPM_DIR/pool.d/$user.conf
244+
245+ if [ -e $FPM_DIR/pool.d/$user.conf ]; then
246+ echo "Pool for \033[32m$user\033[0m user has been successfully created"
247+ else
248+ echo "An error occured during the creating of pool for \033[31m$user\033[0m user"
249+ fi
250+}
251+
252+alias fpmr="$sudo service php5-fpm restart"
253diff --git a/plugins/php-fpm/templates/pool b/plugins/php-fpm/templates/pool
254new file mode 100644
255index 0000000000000000000000000000000000000000..80f6693e04d1d3a833acabe13244ce078c2a36d9
256--- /dev/null
257+++ b/plugins/php-fpm/templates/pool
258@@ -0,0 +1,11 @@
259+[{user}]
260+user = {user}
261+group = {group}
262+
263+listen = 127.0.0.1:{pool_port}
264+
265+pm = dynamic
266+pm.max_children = 10
267+pm.min_spare_servers = 1
268+pm.max_spare_servers = 3
269+pm.max_requests = 100