A shell script

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.