-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatejail.sh
executable file
·85 lines (68 loc) · 1.91 KB
/
createjail.sh
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
#!/bin/sh
iface=bce0
dns=8.8.8.8
usage() {
echo "usage: createjail.sh -n name_of_jail -i ip -p path/to/www/root -h hostname_of_web_site"
}
while getopts "n:i:p:h:" opt; do
case "$opt" in
n) name=$OPTARG ;;
i) ip=$OPTARG ;;
p) path=$OPTARG ;;
h) host=$OPTARG ;;
esac
done
if [ -z "$name" ]; then
echo "need name"; usage ; exit 1
elif [ -z "$ip" ]; then
echo "need ip"; usage ; exit 1
elif [ -z "$path" ]; then
echo "need path"; usage ; exit 1
elif [ -z "$host" ]; then
echo "need host"; usage ; exit 1
fi
echo "Jail info:"
echo " name=${name}"
echo " ip=${ip}"
echo " path=${path}"
echo " host=${host}"
read -p "Create jail (y/N) " REPLY
if [ "$REPLY" = "y" ]; then
echo creating jail $name at $ip
ezjail-admin create $name "$iface|$ip"
echo creating /www directory
mkdir /usr/jails/$name/www
echo mounting www directory
echo $path /usr/jails/$name/www nullfs rw 0 0 >> /etc/fstab
mount -a
echo creating resolv.conf
echo nameserver $dns > /usr/jails/$name/etc/resolv.conf
echo starting jail $name
ezjail-admin start $name
echo installing nginx
ezjail-admin console -e 'env ASSUME_ALWAYS_YES=YES pkg bootstrap' $name
ezjail-admin console -e 'pkg install -y nginx php56 php56-extensions-1.0 php56-pdo_mysql' $name
cp nginx.conf /usr/jails/$name/usr/local/etc/nginx/nginx.conf
echo enabling stuff
echo 'nginx_enable="TRUE"' >> /usr/jails/$name/etc/rc.conf
echo 'php_fpm_enable="TRUE"' >> /usr/jails/$name/etc/rc.conf
echo starting stuff
ezjail-admin console -e 'service nginx start' $name
ezjail-admin console -e 'service php-fpm start' $name
echo creating reverse proxy
mkdir -p /usr/local/etc/nginx/hosted_jails
cat > /usr/local/etc/nginx/hosted_jails/$name.conf \
<<EOF
server {
listen 80;
server_name $host www.$host;
location / {
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_pass http://$ip:80;
}
}
EOF
echo reloading reverse proxy
service nginx reload
fi;