Add Nginx reverse Proxy according to the entry parameter
#!/bin/bash
#set-X
Log_path= "./proc/logs/shellexecute.log"
log_path_back= "./proc/logs/shellexecute.log1"
Nginxbasepath= "/home/netnumen/ems/ums-server/utils/nginx/nginx-1.4.7"
Nginxconfpath= "${nginxbasepath}/conf/nginx.conf"
runnginx= "${nginxbasepath}/run.sh"
stopnginx= "${nginxbasepath}/stop.sh"
app=$ (echo $ | tr-d ' "')
Echo $app
function Execlog () {
If ["$?"-ne 0]
Then
echo "[ERROR] $ (date" +%y-%m-%d%h-%m-%s "), ${1}" >> $log _path
Exit 1
Else
echo "[INFO] $ (date" +%y-%m-%d%h-%m-%s "), ${1}" >> $log _path
Fi
}
function Clean_log ()
{
Declare-i FILESIZE LIMIT
Filesize=0
Filesize= ' stat-c%s ${log_path} '
limit=104857600 #100M Bytes
If [$FILESIZE-gt $LIMIT]
Then
RM-RF ${log_path_back}
MV ${log_path} ${log_path_back}
Fi
}
function Main () {
Clean_log
echo "************************************redirect app to Rdk,update nginx***************************************** ">> $log _path
Execlog "redirect appName: ${app}"
beforeinsertlocation=$ (sed-n "/inside_location_end/=" ${nginxconfpath})
Execlog "COMPUTE insert location num: ${beforeinsertlocation}"
Let Beforeinsertlocation=beforeinsertlocation-1
Execlog "COMPUTE before insert location num: ${beforeinsertlocation}"
insertcontent= "if (\ $uri ~ ^/${app}/) {Proxy_pass http://localhost:5812; Break }"
Execlog "Add content: ${insertcontent}"
existlocation=$ (sed-n "/if (\ $uri ~ ^\/${app}\/) {Proxy_pass http:\/\/localhost:5812; Break }/= "${nginxconfpath})
Execlog "Insert URL existed?location: ${existlocation}"
if [!-n "$existLocation"];then
Sed-i "${beforeinsertlocation}a\ ${insertcontent}" ${nginxconfpath}
Nohup $stopNginx; $runNginx &
Fi
Execlog "sed app url redirt content!"
}
Main
A shell script