-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·96 lines (86 loc) · 2.75 KB
/
install
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
#!/usr/bin/env bash
set -eo pipefail; [[ -n "$PLUSHU_TRACE" ]] && set -x
mkdir -p "$PLUSHU_ROOT/nginx/main"
mkdir -p "$PLUSHU_ROOT/nginx/events"
mkdir -p "$PLUSHU_ROOT/nginx/http"
mkdir -p "$PLUSHU_ROOT/nginx/mail"
mkdir -p "$PLUSHU_ROOT/ssl"
# If there's no pre-existing nginx.conf
if [[ ! -f "$PLUSHU_ROOT/nginx/nginx.conf" ]]; then
# Make a basic conf that reads from the directory for the main block
cat > "$PLUSHU_ROOT/nginx/nginx.conf" <<EOF
include main/*.conf;
EOF
fi
# Make configs in the main block for reading the other 3 block directories
if [[ ! -f "$PLUSHU_ROOT/nginx/main/20_events.conf" ]]; then
cat > "$PLUSHU_ROOT/nginx/main/20_events.conf" <<EOF
events { include events/*.conf; }
EOF
fi
if [[ ! -f "$PLUSHU_ROOT/nginx/main/25_http.conf" ]]; then
cat > "$PLUSHU_ROOT/nginx/main/25_http.conf" <<EOF
http { include http/*.conf; }
EOF
fi
if [[ ! -f "$PLUSHU_ROOT/nginx/main/30_mail.conf" ]]; then
cat > "$PLUSHU_ROOT/nginx/main/30_mail.conf" <<EOF
mail { include mail/*.conf; }
EOF
fi
# Make sure we disable daemonization - docker wants nginx in the foreground
if [[ ! -f "$PLUSHU_ROOT/nginx/main/15_daemon-off.conf" ]]; then
cat > "$PLUSHU_ROOT/nginx/main/15_daemon-off.conf" <<EOF
daemon off;
EOF
fi
if [[ "$EUID" == 0 ]]; then
chown -R "$PLUSHU_USER:" "$PLUSHU_ROOT/nginx"
chown -R "$PLUSHU_USER:" "$PLUSHU_ROOT/ssl"
fi
docker rm -f plushu-nginx >/dev/null 2>&1 || :
docker pull nginx
docker run --name plushu-nginx --net=host \
-v "$PLUSHU_ROOT/nginx:/usr/local/nginx/etc" \
-v "$PLUSHU_ROOT/ssl:/usr/local/nginx/etc/ssl" \
-d --entrypoint=nginx nginx -c /usr/local/nginx/etc/nginx.conf >/dev/null
setup_systemd () {
cat >/etc/systemd/system/multi-user.target.wants/plushu-nginx-container.service \
<<EOF
[Unit]
After=docker.service
[Service]
User=$PLUSHU_USER
ExecStart=docker start plushu-nginx
EOF
}
setup_upstart () {
cat >/etc/init/plushu-nginx-container.conf <<EOF
start on filesystem and started docker
stop on runlevel [!2345]
setuid $PLUSHU_USER
pre-start script
while [ ! -e /var/run/docker.sock ] ; do
command -v inotifywait >/dev/null 2>&1 &&
inotifywait -t 2 -e create /var/run || sleep 1
done
end script
exec docker start plushu-nginx
EOF
if ! command -v inotifywait >/dev/null 2>&1; then
echo "Protip: install inotify-tools to start as soon as possible at boot"
fi
}
if [[ "$EUID" == 0 ]]; then
if command -v systemctl >/dev/null 2>&1; then
setup_systemd
elif command -v initctl >/dev/null 2>&1; then
setup_upstart
else
echo "You don't appear to be using systemd or upstart; we don't have a"
echo "file to start the Nginx container at startup for any other init"
echo "system. Feel free to contribute one."
fi
else
echo "Re-install this plugin as root to set the container to run at boot."
fi