-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallSunServer
executable file
·81 lines (75 loc) · 1.89 KB
/
installSunServer
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
#! /bin/bash
DOMAIN=$1
ETC_NGINX=/etc/nginx
BASE=/opt/sunmonitor
ETC_BASE=/etc/sunmonitor
function InitService(){
cd $BASE
useradd sun
python3 SunServer.py init-service
python3 SunServer.py example
systemctl enable sunserver
systemctl stop sunserver
}
function InitNginx(){
if [ ! -d $ETC_NGINX ]; then
echo "+++ missing NGINX. Aborting creation of a reverse proxy"
else
local fn=$ETC_NGINX/sites-available/$DOMAIN
if [ -e $fn ]; then
echo "already exist: $fn"
else
cat <<EOS >$fn
server {
listen 80;
server_name $DOMAIN;
location / {
return 301 https://$DOMAIN$request_uri;
}
}
server {
listen 443 ssl http2;
ssl_certificate /etc/ssl/certs/$DOMAIN.pem;
ssl_certificate_key /etc/ssl/private/$DOMAIN.key;
server_name $DOMAIN;
root /opt/sunmonitor;
access_log a_sun.log;
error_log e_sun.log;
proxy_ssl_server_name on;
location / {
proxy_pass http://127.0.0.1:48112;
proxy_set_header Host $DOMAIN;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
client_body_in_file_only clean;
client_body_buffer_size 512K;
client_max_body_size 512M;
sendfile on;
send_timeout 60s;
}
}
EOS
cd $ETC_NGINX/sites-enabled
ln -vs ../sites-available/$DOMAIN .
fi
fi
}
function ToDo(){
if [ "$DOMAIN" != 'localhost' ]; then
echo "=== Please create a SSL certificate and put the name in $ETC_NGINX/sites-available/$DOMAIN"
fi
echo "=== Restart the server: systemctl restart sunserver"
ls -1 sunserver.i18n.*
echo "=== Chose the language: ln -s sunserver.i18n.en sunserver.i18n.current"
}
if [ $(id -u) != 0 ]; then
echo "Be root!"
elif [ -z "$DOMAIN" ]; then
echo "Usage: installSunServer DOMAIN"
echo "+++ Missing DOMAIN"
echo "Example: installSunServer sun.example.com"
else
InitService
test $DOMAIN = "localhost" || InitNginx
ToDo
fi