-
Notifications
You must be signed in to change notification settings - Fork 23
/
start_server
131 lines (120 loc) · 4.93 KB
/
start_server
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
#!/bin/bash
# shellcheck shell=bash
# shellcheck disable=SC2016
# shellcheck disable=SC2154
# 自动更新
if [[ "${AUTO_UPDATE}" = "true" ]];then
echo "The automatic update is detected, and the main program is being updated...."
cd /embyExternalUrl && git pull
echo "The main program update is complete."
else
if [[ -z "${GIT_COMMIT_HASH}" ]];then
echo "The GIT_COMMIT_HASH environment variable is not set, will not update the main program."
else
echo "The GIT_COMMIT_HASH environment variable is set, the main program is being updated to the specified commit hash ${GIT_COMMIT_HASH}..."
cd /embyExternalUrl && git checkout ${GIT_COMMIT_HASH}
echo "The main program checkout is complete."
fi
fi
# 软链接ngx_http_js_module.so
if [ ! -e "/etc/nginx/modules/ngx_http_js_module.so" ]; then
ln -s /usr/lib/nginx/modules/ngx_http_js_module.so /etc/nginx/modules/ngx_http_js_module.so
fi
# emby
if [ "${SERVER}" = "emby" ]; then
echo "The emby service is detected, and the configuration file is being linked...."
# 删除原有配置文件
rm -rf /etc/nginx/conf.d /etc/nginx/nginx.conf
# 根据服务获取不同的配置文件
cp -rf /embyExternalUrl/emby2Alist/nginx/conf.d /etc/nginx/conf.d
cp -rf /embyExternalUrl/emby2Alist/nginx/nginx.conf /etc/nginx/nginx.conf
fi
# plex
if [ "${SERVER}" = "plex" ]; then
echo "The plex service is detected, and the configuration file is being linked...."
# 删除原有配置文件
rm -rf /etc/nginx/conf.d /etc/nginx/nginx.conf
# 根据服务获取不同的配置文件
cp -rf /embyExternalUrl/plex2Alist/nginx/conf.d /etc/nginx/conf.d
cp -rf /embyExternalUrl/plex2Alist/nginx/nginx.conf /etc/nginx/nginx.conf
fi
# 判断是否存在配置文件,不存在则创建
if [ ! -e "/opt/constant.js" ]; then
echo "The configuration file is not mapped, creating a new one..."
if [ "${SERVER}" = "plex" ]; then
cp /embyExternalUrl/plex2Alist/nginx/conf.d/exampleConfig/constant-all.js /opt/constant.js
elif [ "${SERVER}" = "emby" ]; then
cp /embyExternalUrl/emby2Alist/nginx/conf.d/exampleConfig/constant-all.js /opt/constant.js
else
echo "The server is not specified, please specify the server name in the environment variable SERVER."
exit 1
fi
fi
# 软连接配置文件
if [ ! -h "/etc/nginx/conf.d/constant.js" ]; then
rm -rf /etc/nginx/conf.d/constant.js
ln -s /opt/constant.js /etc/nginx/conf.d/constant.js
fi
# nginx日志输出到stdout
if [[ -z "${NGINX_LOG_LEVEL}" ]]; then
if ! grep -q "error_log /dev/stdout info;" /etc/nginx/nginx.conf; then
sed -i '/pid\s*\/var\/run\/nginx.pid;/i error_log /dev/stdout info;' /etc/nginx/nginx.conf
fi
if ! grep -q "access_log /dev/stdout main;" /etc/nginx/nginx.conf; then
sed -i '/sendfile\s*on;/i\ access_log /dev/stdout main;' /etc/nginx/nginx.conf
fi
else
if [[ "${NGINX_LOG_LEVEL}" == "error" ]]; then
if ! grep -q "error_log /dev/stdout info;" /etc/nginx/nginx.conf; then
sed -i '/pid\s*\/var\/run\/nginx.pid;/i error_log /dev/stdout info;' /etc/nginx/nginx.conf
fi
elif [[ "${NGINX_LOG_LEVEL}" == "access" ]]; then
if ! grep -q "access_log /dev/stdout main;" /etc/nginx/nginx.conf; then
sed -i '/sendfile\s*on;/i\ access_log /dev/stdout main;' /etc/nginx/nginx.conf
fi
elif [[ "${NGINX_LOG_LEVEL}" == "all" ]]; then
if ! grep -q "error_log /dev/stdout info;" /etc/nginx/nginx.conf; then
sed -i '/pid\s*\/var\/run\/nginx.pid;/i error_log /dev/stdout info;' /etc/nginx/nginx.conf
fi
if ! grep -q "access_log /dev/stdout main;" /etc/nginx/nginx.conf; then
sed -i '/sendfile\s*on;/i\ access_log /dev/stdout main;' /etc/nginx/nginx.conf
fi
fi
fi
# 替换http、https端口
sed -i "s/8091/${NGINX_PORT}/g" "/etc/nginx/conf.d/includes/http.conf"
if [ -n "${NGINX_SSL_PORT}" ]; then
sed -i "s/8095/${NGINX_SSL_PORT}/g" "/etc/nginx/conf.d/includes/https.conf"
fi
# SSL开启
if [ "${SSL_ENABLE}" = "true" ]; then
sed -i '/#\s*include \/etc\/nginx\/conf.d\/includes\/https\.conf;/ {
s/^#//;
a\include \/etc\/nginx\/conf.d\/includes\/https.conf;
d
}' /etc/nginx/conf.d/${SERVER}.conf
echo "SSL is enabled, the https.conf file has been included."
# SSL_DOMAIN、SSL变量替换
cd / && /bin/sh /check_certificate
if [ $? -ne 0 ]; then
echo "In SSL mode, certificate verification failed, exiting the program."
exit 1
fi
# 清空定时任务
crontab -d
# 将新的定时任务写入crontab
echo "${SSL_CRON} cd / && /bin/sh /check_certificate" | crontab -
# 重启cron服务使修改生效
pkill -f crond
/usr/sbin/crond
echo "The scheduled task '${SSL_CRON} cd / && /bin/sh /check_certificate' has been written."
else
sed -i '/include \/etc\/nginx\/conf.d\/includes\/https\.conf;/ {
s/.*//;
a\#include \/etc\/nginx\/conf.d\/includes\/https.conf;
d
}' /etc/nginx/conf.d/${SERVER}.conf
echo "SSL is disabled, the https.conf file has been commented out."
fi
# 后台启动nginx
nginx -g "daemon off;"