This repository has been archived by the owner on Mar 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
web.py
executable file
·140 lines (114 loc) · 3.08 KB
/
web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from fabric.api import *
@task(default=True)
@roles('web')
def main():
print("web.main")
@task
@roles('web')
def add_web(login_asso):
print("Ajout des fichiers de conf apache")
sudo('sed "s/LOGIN/%s/g" /root/modele.suphp > /etc/apache2/custom/%s.suphp' % (login_asso,login_asso))
sudo('echo %s >> /root/assos.list' % (login_asso))
generate_vhost_web()
@task
@roles('web')
def del_web(login_asso):
print("Suppression des fichiers de conf apache")
try:
sudo('rm /etc/apache2/custom/%s.suphp' % login_asso)
except:
pass
try:
sudo('rm /etc/apache2/custom/%s' % login_asso)
except:
pass
try:
sudo('rm /etc/apache2/custom/%s.directory' % login_asso)
except:
pass
try:
sudo('rm /etc/php5/fpm/pool.d/%s.conf' % login_asso)
except:
pass
try:
sudo('rm /etc/apache2/sites-available/%s' % login_asso)
except:
pass
try:
sudo('rm /etc/apache2/sites-enabled/%s' % login_asso)
except:
pass
try:
sudo('rm /etc/php5/fpm/pool.d/custom/%s.conf' % login_asso)
except:
pass
try:
sudo("sed -i '/%s/d' /root/assos.list" % login_asso)
except:
pass
try:
generate_vhost_web()
except:
pass
@task
@roles('web')
def generate_vhost_web():
# Pool php-fpm
sudo("""while read -r line
do
ligne=`echo ${line}|awk -F " " '{print $1}'`
cat > /etc/php5/fpm/pool.d/$ligne.conf <<EOF
[$ligne]
user = $ligne
group = nogroup
listen = /var/run/php-fpm-$ligne.sock
listen.owner = www-data
listen.group = www-data
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
chroot=
chdir = /
php_value[session.save_path] = /sites/sessions/$ligne
php_value[session.cookie_path] = /$ligne
include=/etc/php5/fpm/pool.d/custom/$ligne.conf
EOF
# Config apache
cat > /etc/apache2/sites-available/$ligne <<EOF
Include /etc/apache2/custom/$ligne
Alias /$ligne /sites/$ligne
Alias /php5-$ligne.fastcgi /var/lib/apache2/fastcgi/php5-$ligne.fastcgi
FastCGIExternalServer /var/lib/apache2/fastcgi/php5-$ligne.fastcgi -socket /var/run/php-fpm-$ligne.sock -idle-timeout 60
Action php-script-$ligne /php5-$ligne.fastcgi
<Directory /sites/$ligne>
AddHandler php-script-$ligne .php
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Include /etc/apache2/custom/$ligne.directory
</Directory>
EOF
# Creation des fichiers de config custom
touch /etc/apache2/custom/$ligne.directory
touch /etc/apache2/custom/$ligne
touch /etc/php5/fpm/pool.d/custom/$ligne.conf
# Creation du dossier pour les sessions
mkdir -p /sites/sessions/$ligne
chown $ligne.web /sites/sessions/$ligne
chmod 2750 /sites/sessions/$ligne
# Activation de l'alias
a2ensite $ligne
done < '/root/assos.list'""")
# reload php-fpm
sudo("service php5-fpm reload")
# reload apache2
sudo("service apache2 reload")
@task
@roles('web')
def change_for_python(login_asso):
sudo('sed -i "s/%s/%s python/" /root/assos.list' % (login_asso, login_asso))
@task
@roles('web')
def change_for_php(login_asso):
sudo('sed -i "s/%s python/%s/" /root/assos.list' % (login_asso, login_asso))