@wjwjq/release-helper 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.release/release.conf.yaml +2 -0
- package/dist/cli.js +1 -1
- package/dist/deploy/script/common.sh +36 -29
- package/dist/deploy/script/prompt.sh +6 -0
- package/dist/pack.js +2 -1
- package/dist/prepare.js +14 -4
- package/dist/start_prepare.js +1 -1
- package/package.json +1 -1
- package/src/.release/README.md +0 -73
- package/src/.release/doc//351/203/250/347/275/262/346/211/213/345/206/214.md +0 -418
- package/src/.release/nginx/ca/ca.crt +0 -32
- package/src/.release/nginx/ca/ca.key +0 -54
- package/src/.release/nginx/ca/client.crt +0 -100
- package/src/.release/nginx/ca/client.csr +0 -16
- package/src/.release/nginx/ca/client.p12 +0 -0
- package/src/.release/nginx/ca/client.pem +0 -30
- package/src/.release/nginx/ca/server.crt +0 -101
- package/src/.release/nginx/ca/server.csr +0 -17
- package/src/.release/nginx/ca/server.key +0 -27
- package/src/.release/nginx/ca/server.pem +0 -30
- package/src/.release/nginx/nginx.conf +0 -179
- package/src/.release/release.conf.yaml +0 -15
- package/src/cli.ts +0 -99
- package/src/deploy/pkg/nginx/nginx.logrotate.tpl +0 -14
- package/src/deploy/pkg/nginx/nginx.service.tpl +0 -32
- package/src/deploy/pkg/nginx_binary/compile.sh +0 -39
- package/src/deploy/pkg/nginx_binary/nginx-arm-ssl1.1.1.tar.gz +0 -0
- package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.0.2.tar.gz +0 -0
- package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.1.1.tar.gz +0 -0
- package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl3.0.7.tar.gz +0 -0
- package/src/deploy/script/common.sh +0 -196
- package/src/deploy/script/install.sh +0 -7
- package/src/deploy/script/nginx.sh +0 -265
- package/src/deploy/script/prompt.sh +0 -110
- package/src/deploy/script/readme.md +0 -10
- package/src/deploy/script/upgrade.sh +0 -7
- package/src/logger.ts +0 -18
- package/src/pack.ts +0 -152
- package/src/prepare.ts +0 -120
- package/src/publish.ts +0 -308
- package/src/release.ts +0 -292
- package/src/start_prepare.ts +0 -13
package/src/cli.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { cac } from 'cac'
|
|
2
|
-
import { logger } from './logger'
|
|
3
|
-
import process from 'node:process'
|
|
4
|
-
const cli = cac('release-helper')
|
|
5
|
-
|
|
6
|
-
// init 初始化生成.release目录及相关文件
|
|
7
|
-
// pack 打包命令
|
|
8
|
-
// release 稳定版本发布命令 (包含pack和publish)
|
|
9
|
-
// publish 临时或稳定发布命令
|
|
10
|
-
|
|
11
|
-
// global options
|
|
12
|
-
interface GlobalCLIOptions {
|
|
13
|
-
'--'?: string[]
|
|
14
|
-
c?: boolean | string
|
|
15
|
-
config?: string
|
|
16
|
-
base?: string
|
|
17
|
-
clearScreen?: boolean
|
|
18
|
-
d?: boolean | string
|
|
19
|
-
debug?: boolean | string
|
|
20
|
-
f?: string
|
|
21
|
-
filter?: string
|
|
22
|
-
m?: string
|
|
23
|
-
mode?: string
|
|
24
|
-
force?: boolean
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const filterDuplicateOptions = <T extends object>(options: T) => {
|
|
29
|
-
for (const [key, value] of Object.entries(options)) {
|
|
30
|
-
if (Array.isArray(value)) {
|
|
31
|
-
options[key as keyof T] = value[value.length - 1]
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// init
|
|
37
|
-
cli
|
|
38
|
-
.command('init', 'generate release configuration') // default command
|
|
39
|
-
.action(async (options: GlobalCLIOptions) => {
|
|
40
|
-
filterDuplicateOptions(options)
|
|
41
|
-
try {
|
|
42
|
-
logger.info('start to generate .release configuration ')
|
|
43
|
-
const { prepare } = await import('./prepare');
|
|
44
|
-
await prepare();
|
|
45
|
-
logger.info('done')
|
|
46
|
-
} catch (e) {
|
|
47
|
-
console.error(`release-helper error: `, e)
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
// pack
|
|
51
|
-
cli
|
|
52
|
-
.command('pack', 'start to pack assets') // default command
|
|
53
|
-
// .option('--version <version>', `[version] specify version`)
|
|
54
|
-
.action(async (options: GlobalCLIOptions) => {
|
|
55
|
-
filterDuplicateOptions(options)
|
|
56
|
-
try {
|
|
57
|
-
logger.info('start to pack assets')
|
|
58
|
-
const { pack } = await import('./pack');
|
|
59
|
-
await pack();
|
|
60
|
-
} catch (e) {
|
|
61
|
-
process.exit(1)
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
// publish
|
|
66
|
-
cli
|
|
67
|
-
.command('publish', 'start to publish assets') // default command
|
|
68
|
-
// .option('--version <version>', `[version] specify version`)
|
|
69
|
-
.action(async (options: GlobalCLIOptions) => {
|
|
70
|
-
filterDuplicateOptions(options)
|
|
71
|
-
// publish
|
|
72
|
-
try {
|
|
73
|
-
logger.info('start to publish assets')
|
|
74
|
-
const { release } = await import('./release');
|
|
75
|
-
await release(true);
|
|
76
|
-
} catch (e) {
|
|
77
|
-
process.exit(1)
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
//release
|
|
82
|
-
cli
|
|
83
|
-
.command('release', 'start to release assets') // default command
|
|
84
|
-
// .option('--version <version>', `[version] specify version`)
|
|
85
|
-
.action(async (options: GlobalCLIOptions) => {
|
|
86
|
-
filterDuplicateOptions(options)
|
|
87
|
-
try {
|
|
88
|
-
logger.info('start to release assets')
|
|
89
|
-
const { release } = await import('./release');
|
|
90
|
-
await release();
|
|
91
|
-
} catch (e) {
|
|
92
|
-
process.exit(1)
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
cli.help()
|
|
97
|
-
cli.version('0.0.1')
|
|
98
|
-
|
|
99
|
-
cli.parse()
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/var/log/__app_name__/*.log {
|
|
2
|
-
daily
|
|
3
|
-
missingok
|
|
4
|
-
minsize 100M
|
|
5
|
-
rotate 3
|
|
6
|
-
compress
|
|
7
|
-
delaycompress
|
|
8
|
-
notifempty
|
|
9
|
-
create 0644 __user__ __usergroup__
|
|
10
|
-
sharedscripts
|
|
11
|
-
postrotate
|
|
12
|
-
[ -f __pid_file__ ] && kill -USR1 `cat __pid_file__`
|
|
13
|
-
endscript
|
|
14
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
[Unit]
|
|
2
|
-
Description=nginx.service
|
|
3
|
-
After=syslog.target network-online.target remote-fs.target nss-lookup.target
|
|
4
|
-
Wants=network-online.target
|
|
5
|
-
|
|
6
|
-
[Service]
|
|
7
|
-
# 应用启动使用的用户及用户组,需各组件手动修改
|
|
8
|
-
User=_user_
|
|
9
|
-
Group=_user_group_
|
|
10
|
-
|
|
11
|
-
Environment="LOGPATH=_log_path_" "LOGFILE=_log_file_" "LOGROTATEDELAY=2592000000" "CONFS=_conf_path_" "VERSION=_version_"
|
|
12
|
-
|
|
13
|
-
# Disable service start and stop timeout logic of systemd for mysqld service.
|
|
14
|
-
TimeoutSec=0
|
|
15
|
-
|
|
16
|
-
# Execute pre and post scripts as root
|
|
17
|
-
PermissionsStartOnly=true
|
|
18
|
-
|
|
19
|
-
# 应用安装目录,需手动修改
|
|
20
|
-
WorkingDirectory=/etc/nginx
|
|
21
|
-
|
|
22
|
-
[Service]
|
|
23
|
-
Type=forking
|
|
24
|
-
PIDFile=_pid_file_
|
|
25
|
-
ExecStart=_exec_cmd_
|
|
26
|
-
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat _pid_file_)"
|
|
27
|
-
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat _pid_file_)"
|
|
28
|
-
|
|
29
|
-
PrivateTmp=true
|
|
30
|
-
|
|
31
|
-
[Install]
|
|
32
|
-
WantedBy=multi-user.target
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# current nginx source code version 1.22.1
|
|
3
|
-
|
|
4
|
-
./configure \
|
|
5
|
-
--prefix=/etc/nginx \
|
|
6
|
-
--conf-path=/etc/nginx/nginx.conf \
|
|
7
|
-
--error-log-path=/var/log/nginx/error.log \
|
|
8
|
-
--http-log-path=/var/log/nginx/access.log \
|
|
9
|
-
--pid-path=/var/run/nginx.pid \
|
|
10
|
-
--lock-path=/var/run/nginx/nginx.lock \
|
|
11
|
-
--with-http_ssl_module \
|
|
12
|
-
--with-http_v2_module \
|
|
13
|
-
--with-http_gzip_static_module \
|
|
14
|
-
--with-http_stub_status_module \
|
|
15
|
-
--with-stream \
|
|
16
|
-
--with-pcre
|
|
17
|
-
|
|
18
|
-
make
|
|
19
|
-
|
|
20
|
-
make install
|
|
21
|
-
|
|
22
|
-
echo '------------------compile and install done----------------------------'
|
|
23
|
-
|
|
24
|
-
arch=$(uname -m)
|
|
25
|
-
ssl_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
|
|
26
|
-
|
|
27
|
-
if [[ -z "${arch}" ]]; then
|
|
28
|
-
arch="x86_64"
|
|
29
|
-
fi
|
|
30
|
-
|
|
31
|
-
if [[ -z "${ssl_version}" ]]; then
|
|
32
|
-
ssl_version="1.0.2"
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
cd /etc || exit
|
|
36
|
-
|
|
37
|
-
tar -zcvf nginx-"$arch"-ssl"$ssl_version".tar.gz nginx/ -C /root
|
|
38
|
-
|
|
39
|
-
echo "-----------pack at: /root nginx-"$arch"-ssl"$ssl_version".tar.gz--------------"
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# 获取脚本的父目录
|
|
3
|
-
project_path=$(echo "$basepath" | sed -e "s/\/script//")
|
|
4
|
-
|
|
5
|
-
# 请勿修改此处, 此处将在打包时自动替换
|
|
6
|
-
app_name=__APP_NAME__
|
|
7
|
-
|
|
8
|
-
# 静态资源存放目录 eg: /opt/posidon-frontend/
|
|
9
|
-
install_path=__INSTALL_PATH__
|
|
10
|
-
user=__USER__
|
|
11
|
-
usergroup=__USER_GROUP__
|
|
12
|
-
|
|
13
|
-
execute_log_path="/var/log/${app_name}_script_execute_logs"
|
|
14
|
-
|
|
15
|
-
log() {
|
|
16
|
-
now=$(date "+%Y-%m-%d %H:%M:%S")
|
|
17
|
-
echo "$now: $1"
|
|
18
|
-
echo "$now: [info] $1" >>"$execute_log_path"
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
log_success() {
|
|
22
|
-
now=$(date "+%Y-%m-%d %H:%M:%S")
|
|
23
|
-
echo "$(tput setaf 2)""$now": "$1""$(tput sgr0)"
|
|
24
|
-
echo "$now: [success] $1" >>"$execute_log_path"
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
log_error() {
|
|
28
|
-
now=$(date "+%Y-%m-%d %H:%M:%S")
|
|
29
|
-
echo "$(tput setaf 1)""$now": "$1" "$(tput sgr0)"
|
|
30
|
-
echo "$now: [error] $1" >>"$execute_log_path"
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
log "-----------execute ${app_name} script-------------"
|
|
34
|
-
|
|
35
|
-
source "$basepath"/prompt.sh
|
|
36
|
-
|
|
37
|
-
if [[ $(whoami) != "root" ]]; then
|
|
38
|
-
echo "user:root is required!"
|
|
39
|
-
exit 1
|
|
40
|
-
fi
|
|
41
|
-
|
|
42
|
-
if [[ -z "${install_path}" ]]; then
|
|
43
|
-
echo "install path not found"
|
|
44
|
-
exit 1
|
|
45
|
-
fi
|
|
46
|
-
|
|
47
|
-
echo "install_path: ${install_path}"
|
|
48
|
-
|
|
49
|
-
source "$basepath"/nginx.sh
|
|
50
|
-
|
|
51
|
-
# 创建用户
|
|
52
|
-
create_user_csri() {
|
|
53
|
-
user=$user
|
|
54
|
-
group=$usergroup
|
|
55
|
-
|
|
56
|
-
#create group if not exists
|
|
57
|
-
grep "^$group" /etc/group >&/dev/null
|
|
58
|
-
if [ $? -ne 0 ]; then
|
|
59
|
-
groupadd $group
|
|
60
|
-
fi
|
|
61
|
-
|
|
62
|
-
#create user if not exists
|
|
63
|
-
grep "^$user" /etc/passwd >&/dev/null
|
|
64
|
-
if [ $? -ne 0 ]; then
|
|
65
|
-
useradd -g $group $user
|
|
66
|
-
fi
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
has_nginx_installed=1
|
|
70
|
-
|
|
71
|
-
# 检查 nginx 是否已安装
|
|
72
|
-
if command -v nginx >/dev/null 2>&1; then
|
|
73
|
-
# echo "Nginx is installed."
|
|
74
|
-
has_nginx_installed=1
|
|
75
|
-
# # 检查 nginx 服务是否正在运行
|
|
76
|
-
# if pgrep nginx >/dev/null 2>&1; then
|
|
77
|
-
# echo "Nginx is running."
|
|
78
|
-
# else
|
|
79
|
-
# echo "Nginx is installed but not running."
|
|
80
|
-
# fi
|
|
81
|
-
else
|
|
82
|
-
# echo "Nginx is not installed."
|
|
83
|
-
has_nginx_installed=0
|
|
84
|
-
fi
|
|
85
|
-
|
|
86
|
-
get_old_version() {
|
|
87
|
-
if [ -f "$install_path""version" ]; then
|
|
88
|
-
old_version=$(sed -n '1p' "$install_path""version")
|
|
89
|
-
|
|
90
|
-
echo "$old_version"
|
|
91
|
-
fi
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
install_assets() {
|
|
95
|
-
|
|
96
|
-
# 拷贝静态资源
|
|
97
|
-
cp -rf "${project_path}"/pkg/version "$install_path"
|
|
98
|
-
|
|
99
|
-
mkdir -p "$install_path"assets
|
|
100
|
-
|
|
101
|
-
cp -rf "${project_path}"/pkg/assets/* "$install_path"assets
|
|
102
|
-
|
|
103
|
-
# # 对比行数并合并
|
|
104
|
-
# if [ -f "${backup_path}/settings" ]; then
|
|
105
|
-
# cat $backup_path/settings | sed '/^$/d' >>./settings
|
|
106
|
-
# cat $install_path/settings | sed '/^$/d' >>./settings_new
|
|
107
|
-
|
|
108
|
-
# diffLines=$(diff ./settings ./settings_new | awk 'END{print NR}')
|
|
109
|
-
|
|
110
|
-
# if ((diffLines > 0)); then
|
|
111
|
-
# echo '-------合并前:old--------'
|
|
112
|
-
# cat ./settings
|
|
113
|
-
# old_total_line=$(awk 'END{print NR}' ./settings)
|
|
114
|
-
# start=$(($old_total_line + 1))
|
|
115
|
-
|
|
116
|
-
# echo '-------合并前: new--------'
|
|
117
|
-
# cat ./settings_new
|
|
118
|
-
# total_line=$(awk 'END{print NR}' ./settings_new)
|
|
119
|
-
|
|
120
|
-
# sed -n "${start},${total_line}p" ./settings_new >>./settings
|
|
121
|
-
# echo '---------- 合并后 ----------'
|
|
122
|
-
# cat ./settings
|
|
123
|
-
|
|
124
|
-
# mv -f ./settings $install_path
|
|
125
|
-
# rm -rf ./settings_new
|
|
126
|
-
|
|
127
|
-
# echo "$(tput setaf 2)"settings 已合并,注意检查"$(tput sgr0)"
|
|
128
|
-
# fi
|
|
129
|
-
# fi
|
|
130
|
-
|
|
131
|
-
log_success "$install_path"assets/settings 已覆盖,请注意对比差异
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
start() {
|
|
136
|
-
# 未安装
|
|
137
|
-
if ((has_nginx_installed == 0)); then
|
|
138
|
-
install_nginx_binary
|
|
139
|
-
|
|
140
|
-
if [[ $? != 0 ]]; then
|
|
141
|
-
echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
|
|
142
|
-
exit 1
|
|
143
|
-
fi
|
|
144
|
-
fi
|
|
145
|
-
|
|
146
|
-
# 已安装 询问是否更新nginx
|
|
147
|
-
if ((has_nginx_installed == 1)); then
|
|
148
|
-
while true; do
|
|
149
|
-
read -r -p "Nginx has been installed, re-install it?[Y/N]" yn
|
|
150
|
-
case $yn in
|
|
151
|
-
[Yy]*)
|
|
152
|
-
install_nginx_binary
|
|
153
|
-
|
|
154
|
-
if [[ $? != 0 ]]; then
|
|
155
|
-
echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
|
|
156
|
-
exit 1
|
|
157
|
-
fi
|
|
158
|
-
break
|
|
159
|
-
;;
|
|
160
|
-
[Nn]*) break ;;
|
|
161
|
-
*) echo "Please answer yes or no." ;;
|
|
162
|
-
esac
|
|
163
|
-
done
|
|
164
|
-
fi
|
|
165
|
-
|
|
166
|
-
# 创建用户
|
|
167
|
-
create_user_csri
|
|
168
|
-
|
|
169
|
-
now=$(date "+%Y-%m-%d_%H:%M:%S")
|
|
170
|
-
old_version=$(get_old_version)
|
|
171
|
-
|
|
172
|
-
#备份整个服务 eg: /opt/posidon-frontend
|
|
173
|
-
if [[ -n "${old_version}" ]]; then
|
|
174
|
-
parent_store_path=$(echo "$install_path" | sed -e "s/\/${app_name}//")
|
|
175
|
-
backup_path=$parent_store_path""$app_name"_"$old_version"_"$now
|
|
176
|
-
echo "${app_name} assets backup at: $backup_path"
|
|
177
|
-
mv "$install_path" "$backup_path"
|
|
178
|
-
fi
|
|
179
|
-
|
|
180
|
-
mkdir -p "$install_path"
|
|
181
|
-
|
|
182
|
-
copy_nginx_conf_and_write_verison
|
|
183
|
-
add_nginx_service
|
|
184
|
-
add_log_rotate
|
|
185
|
-
install_assets
|
|
186
|
-
|
|
187
|
-
# 修改所属用户
|
|
188
|
-
chown -R $user:$usergroup "$install_path"
|
|
189
|
-
chmod 744 -R "$install_path"
|
|
190
|
-
|
|
191
|
-
if [[ $? == 0 ]]; then
|
|
192
|
-
log_success "posidon-frontend deployed successfully"
|
|
193
|
-
else
|
|
194
|
-
log_error "posidon-frontend deployment failed"
|
|
195
|
-
fi
|
|
196
|
-
}
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# 安装包所在路径
|
|
4
|
-
pkg_path="${project_path}/pkg"
|
|
5
|
-
|
|
6
|
-
#------------------------------------ nginx服务配置文件服务 start----------------------------------
|
|
7
|
-
# 配置文件所在路径
|
|
8
|
-
new_nginx_conf_path="${pkg_path}/nginx"
|
|
9
|
-
|
|
10
|
-
# 指定安装目录
|
|
11
|
-
nginx_conf_install_path="$prefix/opt/${app_name}/nginx/"
|
|
12
|
-
|
|
13
|
-
# nginx服务配置文件路径
|
|
14
|
-
nginx_conf_path="${nginx_conf_install_path}nginx.conf"
|
|
15
|
-
|
|
16
|
-
# asset_path="$prefix/opt/posidon-frontend/"
|
|
17
|
-
nginx_info_path="/var/log/${app_name}"
|
|
18
|
-
nginx_log_file="nginx.log"
|
|
19
|
-
#不放在var/run 是因为重启后 var/run/下面的文件及目录会被清除
|
|
20
|
-
nginx_pid_file_path="$nginx_info_path/nginx.pid"
|
|
21
|
-
|
|
22
|
-
conf_version=$(awk '{print $1}' "${pkg_path}"/version)
|
|
23
|
-
echo "$conf_version"
|
|
24
|
-
|
|
25
|
-
copy_nginx_conf_and_write_verison() {
|
|
26
|
-
mkdir -p "$nginx_conf_install_path"
|
|
27
|
-
# 创建pid目录. 创建日志目录
|
|
28
|
-
mkdir -p $nginx_info_path
|
|
29
|
-
touch $nginx_info_path/$nginx_log_file
|
|
30
|
-
chown -R $user:$usergroup $nginx_info_path
|
|
31
|
-
chmod 744 -R $nginx_info_path
|
|
32
|
-
|
|
33
|
-
access_log_super="access_log /dev/stdout main"
|
|
34
|
-
error_log_super="error_log /dev/stderr warn"
|
|
35
|
-
access_log="access_log $nginx_info_path/$nginx_log_file main"
|
|
36
|
-
error_log="error_log $nginx_info_path/$nginx_log_file"
|
|
37
|
-
pid_file="pid $nginx_pid_file_path"
|
|
38
|
-
|
|
39
|
-
exec=$(get_exec_path)
|
|
40
|
-
|
|
41
|
-
# if [ -f "$nginx_conf_path" ]; then
|
|
42
|
-
# old_version=$(sed -n '1p' "$nginx_conf_path" | sed 's/# version: //' | sed "s/\s\+//g")
|
|
43
|
-
|
|
44
|
-
# if [[ -n "${old_version}" ]]; then
|
|
45
|
-
# now=$(date "+%Y-%m-%d_%H:%M:%S")
|
|
46
|
-
|
|
47
|
-
# # echo "nginx_"$old_version"_"$now".conf"
|
|
48
|
-
# mv "$nginx_conf_path" "${nginx_conf_install_path}"/"$app_name".nginx_"$old_version"_"$now".conf
|
|
49
|
-
# fi
|
|
50
|
-
# fi
|
|
51
|
-
|
|
52
|
-
#nginx -v nginx代码内部使用的stderr输出, 此处需要转换为stdout
|
|
53
|
-
nginx_version=$($exec -v 2>&1)
|
|
54
|
-
|
|
55
|
-
tmp_file='./nginx/nginx.conf'
|
|
56
|
-
cp -rf "$new_nginx_conf_path" ./
|
|
57
|
-
|
|
58
|
-
sed -i "1i\# ${nginx_version}" $tmp_file
|
|
59
|
-
sed -i "1i\# version: ${conf_version}" $tmp_file
|
|
60
|
-
|
|
61
|
-
if [[ -n "${prefix}" ]]; then
|
|
62
|
-
n=$(grep -wn "mime.types" $tmp_file | awk -F: '{print $1}' | sed -n 1p)
|
|
63
|
-
sed -i "${n}c include conf/mime.types;" $tmp_file
|
|
64
|
-
fi
|
|
65
|
-
|
|
66
|
-
# n=$(grep -wn "__root__" $tmp_file | awk -F: '{print $1}' | sed -n 1p)
|
|
67
|
-
# if [[ -n "${n}" ]]; then
|
|
68
|
-
# sed -i "${n}c root ${asset_path};" $tmp_file
|
|
69
|
-
# fi
|
|
70
|
-
|
|
71
|
-
# 替换日志输出路径方式
|
|
72
|
-
n=$(grep -wn "#ERROR_LOG_PLACEHOLDER" $tmp_file | awk -F: '{print $1}' | sed -n 1p)
|
|
73
|
-
if [[ -n "${n}" ]]; then
|
|
74
|
-
sed -i "${n}c ${error_log};" $tmp_file
|
|
75
|
-
# if ((mode == 2)); then
|
|
76
|
-
# sed -i "${n}c ${error_log};" $tmp_file
|
|
77
|
-
# else
|
|
78
|
-
# sed -i "${n}c ${error_log_super};" $tmp_file
|
|
79
|
-
# fi
|
|
80
|
-
fi
|
|
81
|
-
|
|
82
|
-
n=$(grep -wn "#ACCESS_LOG_PLACEHOLDER" $tmp_file | awk -F: '{print $1}' | sed -n 1p)
|
|
83
|
-
if [[ -n "${n}" ]]; then
|
|
84
|
-
sed -i "${n}c ${access_log};" $tmp_file
|
|
85
|
-
# if ((mode == 2)); then
|
|
86
|
-
# sed -i "${n}c ${access_log};" $tmp_file
|
|
87
|
-
# else
|
|
88
|
-
# sed -i "${n}c ${access_log_super};" $tmp_file
|
|
89
|
-
# fi
|
|
90
|
-
fi
|
|
91
|
-
|
|
92
|
-
n=$(grep -wn "#PID_FILE_PALCEHOLDER" $tmp_file | awk -F: '{print $1}' | sed -n 1p)
|
|
93
|
-
if [[ -n "${n}" ]]; then
|
|
94
|
-
sed -i "${n}c ${pid_file};" $tmp_file
|
|
95
|
-
# 非supervisorctl
|
|
96
|
-
# if ((mode == 2)); then
|
|
97
|
-
# sed -i "${n}c ${pid_file};" $tmp_file
|
|
98
|
-
# fi
|
|
99
|
-
fi
|
|
100
|
-
|
|
101
|
-
n=$(grep -wn "daemon off;" $tmp_file | awk -F: '{print $1}' | sed -n 1p)
|
|
102
|
-
if [[ -n "${n}" ]]; then
|
|
103
|
-
# 非supervisorctl
|
|
104
|
-
if ((mode == 2)); then
|
|
105
|
-
sed -i "${n}c daemon on;" $tmp_file
|
|
106
|
-
fi
|
|
107
|
-
fi
|
|
108
|
-
|
|
109
|
-
# 拷贝整个nginx目录
|
|
110
|
-
mv -fb ./nginx/* "$nginx_conf_install_path"
|
|
111
|
-
|
|
112
|
-
mkdir -p /data/command/
|
|
113
|
-
log "nginx start command: $(get_exec_cmd)"
|
|
114
|
-
echo "$exec -c $nginx_conf_path" >/data/command/nginx
|
|
115
|
-
|
|
116
|
-
if [[ $? == 0 ]]; then
|
|
117
|
-
log_success "$conf_version $nginx_conf_path replaced successfully!"
|
|
118
|
-
else
|
|
119
|
-
log_error "$conf_version $nginx_conf_path replaced failed!"
|
|
120
|
-
fi
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
get_exec_path() {
|
|
124
|
-
cmd=''
|
|
125
|
-
if [[ -n "${prefix}" ]]; then
|
|
126
|
-
cmd="${nginx_conf_install_path}/sbin/nginx"
|
|
127
|
-
else
|
|
128
|
-
cmd="/usr/sbin/nginx"
|
|
129
|
-
fi
|
|
130
|
-
|
|
131
|
-
echo "$cmd"
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
get_exec_cmd() {
|
|
135
|
-
exec=$(get_exec_path)
|
|
136
|
-
|
|
137
|
-
echo "$exec -c $nginx_conf_path"
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
add_nginx_service() {
|
|
141
|
-
#添加到服务
|
|
142
|
-
exec_cmd="$(get_exec_cmd) -e $nginx_info_path/$nginx_log_file"
|
|
143
|
-
cp "$pkg_path"/nginx/nginx.service.tpl ./nginx.service
|
|
144
|
-
|
|
145
|
-
check_cmd="$exec -t -c $nginx_conf_path -e $nginx_info_path/$nginx_log_file"
|
|
146
|
-
version=$(echo "$conf_version" | grep -oP '\d+\.\d+\.\d+')
|
|
147
|
-
|
|
148
|
-
sed -i "s#_user_group_#$usergroup#g" ./nginx.service
|
|
149
|
-
sed -i "s#_user_#$user#g" ./nginx.service
|
|
150
|
-
sed -i "s#_exec_cmd_#$exec_cmd #g" ./nginx.service
|
|
151
|
-
sed -i "s#_log_path_#$nginx_info_path#g" ./nginx.service
|
|
152
|
-
sed -i "s#_log_file_#$nginx_log_file#g" ./nginx.service
|
|
153
|
-
sed -i "s#_conf_path_#$nginx_conf_path#g" ./nginx.service
|
|
154
|
-
sed -i "s#_version_#$version#g" ./nginx.service
|
|
155
|
-
sed -i "s#_pid_file_#$nginx_pid_file_path#g" ./nginx.service
|
|
156
|
-
#sed -i "s#_start_check_#$check_cmd#g" ./nginx.service
|
|
157
|
-
|
|
158
|
-
if ((mode == 2)); then
|
|
159
|
-
# systemctl enable nginx
|
|
160
|
-
cp ./nginx.service /usr/lib/systemd/system/"$app_name".nginx.service
|
|
161
|
-
systemctl daemon-reload
|
|
162
|
-
|
|
163
|
-
log_success "add ${app_name}.nginx.service to /usr/lib/systemd/system/"
|
|
164
|
-
else
|
|
165
|
-
rm -rf /usr/lib/systemd/system/"$app_name".nginx.service
|
|
166
|
-
fi
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
add_log_rotate(){
|
|
170
|
-
mkdir -p /etc/logrotate.d
|
|
171
|
-
|
|
172
|
-
rm -rf /etc/logrotate.d/${app_name}.nginx
|
|
173
|
-
#添加日志翻转
|
|
174
|
-
cp "$pkg_path"/nginx/nginx.logrotate.tpl ./nginx.logrotate
|
|
175
|
-
|
|
176
|
-
sed -i "s#__usergroup__#$usergroup#g" ./nginx.logrotate
|
|
177
|
-
sed -i "s#__user__#$user#g" ./nginx.logrotate
|
|
178
|
-
sed -i "s#__app_name__#$app_name#g" ./nginx.logrotate
|
|
179
|
-
sed -i "s#__pid_file__#$nginx_pid_file_path#g" ./nginx.logrotate
|
|
180
|
-
|
|
181
|
-
cp -f ./nginx.logrotate /etc/logrotate.d/${app_name}.nginx
|
|
182
|
-
}
|
|
183
|
-
#------------------------------------ nginx服务配置文件服务 end----------------------------------
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
#------------------------------------ nginx 可执行程序相关 start----------------------------------
|
|
187
|
-
# 指定安装目录
|
|
188
|
-
nginx_binary_install_path="/etc/nginx/"
|
|
189
|
-
|
|
190
|
-
mkdir -p "$nginx_binary_install_path"
|
|
191
|
-
|
|
192
|
-
# 安装包所在路径
|
|
193
|
-
nginx_binary_pkg_path="${pkg_path}/nginx_binary"
|
|
194
|
-
|
|
195
|
-
open_port_80() {
|
|
196
|
-
# 查看防火墙是否开启
|
|
197
|
-
systemctl status firewalld
|
|
198
|
-
# 若未开启则开启
|
|
199
|
-
systemctl start firewalld
|
|
200
|
-
|
|
201
|
-
# 查看所有开启的端口
|
|
202
|
-
#firewall-cmd --list-ports
|
|
203
|
-
|
|
204
|
-
# 开启nginx默认80端口(关键步骤一)
|
|
205
|
-
firewall-cmd --zone=public --add-port=80/tcp --permanent
|
|
206
|
-
|
|
207
|
-
# 重启防火墙(关键步骤二)
|
|
208
|
-
firewall-cmd --reload
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
# 安装nginx可执行程序
|
|
212
|
-
install_nginx_binary() {
|
|
213
|
-
log "install nginx to path: ${nginx_binary_install_path}"
|
|
214
|
-
|
|
215
|
-
arch=$(uname -m)
|
|
216
|
-
ssl_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
|
|
217
|
-
|
|
218
|
-
if [[ -z "${arch}" ]]; then
|
|
219
|
-
arch="x86_64"
|
|
220
|
-
fi
|
|
221
|
-
|
|
222
|
-
if [[ $arch == arm* ]] || [[ $arch = aarch64 ]]; then
|
|
223
|
-
arch="arm"
|
|
224
|
-
fi
|
|
225
|
-
|
|
226
|
-
if [[ "${ssl_version}" == "1.0" ]]; then
|
|
227
|
-
ssl_version="1.0.2"
|
|
228
|
-
fi
|
|
229
|
-
|
|
230
|
-
if [[ "${ssl_version}" == "1.1" ]]; then
|
|
231
|
-
ssl_version="1.1.1"
|
|
232
|
-
fi
|
|
233
|
-
|
|
234
|
-
if [[ "${ssl_version}" == "3.0" ]]; then
|
|
235
|
-
ssl_version="3.0.7"
|
|
236
|
-
fi
|
|
237
|
-
|
|
238
|
-
if [[ -z "${ssl_version}" ]]; then
|
|
239
|
-
ssl_version="1.0.2"
|
|
240
|
-
fi
|
|
241
|
-
|
|
242
|
-
pkg="$nginx_binary_pkg_path"/nginx-"$arch"-ssl"$ssl_version".tar.gz
|
|
243
|
-
|
|
244
|
-
if [ ! -f "$pkg" ]; then
|
|
245
|
-
log_error "Fatal error: nginx-$arch-ssl$ssl_version.tar.gz not matched! contact developer!"
|
|
246
|
-
exit 1
|
|
247
|
-
fi
|
|
248
|
-
|
|
249
|
-
log "current arch: $arch, current ssl_version: $ssl_version"
|
|
250
|
-
|
|
251
|
-
tar -zxvhf "$pkg" -C "$nginx_binary_install_path" --strip-components 1
|
|
252
|
-
# 检测是否安装成功
|
|
253
|
-
if [[ $? == 0 ]]; then
|
|
254
|
-
log_success "nginx installation successfully!"
|
|
255
|
-
else
|
|
256
|
-
log_error "nginx installation failed!"
|
|
257
|
-
fi
|
|
258
|
-
|
|
259
|
-
ln -sf "$nginx_binary_install_path"sbin/nginx /usr/sbin/nginx
|
|
260
|
-
|
|
261
|
-
# 修改/etc/nginx 用户(组)
|
|
262
|
-
chown -R $user:$usergroup "$nginx_binary_install_path"
|
|
263
|
-
chmod 744 -R "$nginx_binary_install_path"
|
|
264
|
-
}
|
|
265
|
-
#------------------------------------ nginx 可执行程序相关 end ----------------------------------
|