Project Release Script-go

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
#!/bin/bashexport path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binclearprintf "# Name:downtown_     shell_deploy_script## Purpose:deploy tar.gz to the host## notes:# 1 Upload your tar.gz file to the Path/data/source # #  2./script_name filename.postfix# for example:./new_update_nodejs_tar_update.sh buffetmealapi.tar.gz## Return codes:# Startup time Launcher # 14:26 nodejs######################################################## "#check Userif [$ (id-u)! =" 0 "]then E   Cho "Error:you must is root to run this script!!!" Exit 1fiif [-z] $ "];thenecho" Usage:script.sh file.tar.gz "exitelseecho" execution file name: $ "fi#defineproject_name_file=$1 #buf fetmealapi.tar.gzproject_name=${project_name_file%%.*} #buffetmealapiINIT_SCRIPT_URL =/data/sourceconfig_url=/     data/configproject_name_suffix=${project_name_file#*.} #tar. gz# #工程目录PROJECT_NODE_APP_PATH = "/data/app/eshine/$Project _name" # #源配置文件模板目录PROJECT_NODE_APP_CONFIG_ Templates_path= "/data/app/eshine/$Project _name/config-templates" #/data/app/eshine/storeapi/config-templates/# #目标配置文件目录PROJECT_NODE_APP_CONFD_PATH = "/data/app/confd/config/$Project _  Name "#/data/app/confd/config/storeapifunction_deploy_tar_gz () {source/etc/profile echo-e" \033[31m make Sure REMOVE This HOST is---lvs---lvs,5 seconds to think? Press CTRL + C to cancel \033[0m "Sleep 2 #停止shell应用ps-ef | grep/data/app/eshine/$Project _name | grep-v grep | awk ' {p Rint "Kill-9" | Bash Sleep 3 #创建备份目录 mkdir-p/data/backup/$ (date +%y%m%d%h%m) #创建app工作目录 mkdir-p/data/app/eshine #更新前备份 if [-D    "/data/app/eshine/$Project _name"];then mv/data/app/eshine/$Project _name/data/backup/$ (date +%y%m%d%h%m)/Echo "###############################################################" echo-e "# $Project _name backup Compla                 ted! # "echo" ############################################################### "Else echo" ##########################       ##################################### "ECHO-E" #     Warning: $Project _name does not exist! # "echo" ############################################################### "fi #解压新app包 cd/data/source TAR-ZXF $Project _name_file-c./#部署应用 rm-rf/data/app/eshine/$Project _name mv $Project _name/data/app/eshine/#更新配置文件并启用conf D Monitoring # First to end the project's CONFD process Ps-ef | grep confd/config/$Project _name | Grep-v grep | awk ' {print ' kill-9 ' $ ' | Bashecho "===============================" echo "[CONFD] for $Project _name killed" echo "============================= = = "#清理confd项目目录rm-rf $PROJECT _node_app_confd_pathmkdir-p $PROJECT _node_app_confd_path/conf.dmkdir-p $PROJECT _node _app_confd_path/templatesls $PROJECT _node_app_confd_path# #复制配置文件到指定目录find $PROJECT _node_app_config_templates_ Path-type f-name "* *"-exec cp-fr {} $PROJECT _node_app_confd_path/templates \;echo ========templates copied=========== ==========ls $PROJECT _node_app_confd_path/*/*echo ========templates copied=====================# #生成模式化文件format_ standard.txt# #格式为: FileName File path # #清空format_standard. txt file echo "" > $PROJECT _node_app_confd_path/format_standard.txt# #提取PROJECT_NODE_ App_config_templates_path directory as a variable, and presents all Filenames project_node_app_config_templates_l2_list= ' CD $PROJECT _node_app_ Config_templates_path; Find $PWD | Xargs LS-DL | Grep-v "^d" | awk ' begin{fs= '/'} {print $ (NF-1)/' $NF} ' #i代表的是 $PROJECT the relative path of all files output by _node_app_config_templates_l2_list Echo ===== ===config file need to be generate =====================echo "${project_node_app_config_templates_l2_list}" echo ====== ==config file need to is generate =====================CD $PROJECT _node_app_confd_pathfor i in $PROJECT _node_app_config_ Templates_l2_listdo if [-F $PROJECT _node_app_path/$i];then find $PROJECT _node_app_path/$i-type f-name "* *" |awk ' Begin{fs= "/"} {printf ("%30s\t%s\n", $NF, $)} ' >> $PROJECT _node_app_confd_path/format_standard.txt fidonefor I In $PROJECT _node_app_config_templates_l2_listdo if [-F $PROJECT _node_app_path/config/$i];then Find $PROJECT _node_app_path/config/$i-type f-name "* *" |awk ' begin{fs= "/"} {printf ("%30s\t%s\n", $NF, $)} ' >> $PROJECT _node_app_ Confd_path/format_standard.txt Fidoneecho "################# format_standard.txt############" Cat $PROJECT _node_app _confd_path/format_standard.txtecho "################# format_standard.txt############" # #遍历格式化文件并生成模板文件cd $ Project_node_app_confd_pathcat format_standard.txt |awk ' nr>1 ' |while read f_config_name F_CONFIG_PATHdo # #生成模板文件 CA T << EOF > conf.d/$F _config_name.toml[template] #模板文件, modify it based on src = "$F _config_name" #目标文件地址dest = "$F _config_ PATH "#keys是在etcd上订阅消息的前缀keys = [" ",] #更新配置后的命令reload_cmd ="/data/scripts/restart-${project_name}_guard.sh "eofdone# Shows the number of CONFD processes for this project Ps-ef | grep confd/config/$Project _name | Grep-v grep | Wc-lexport Etcdctl_api=2nohup/data/app/confd/bin/confd-config-file/data/app/confd/confd.config-confdir/data/app /confd/config/$Project _name/-username root-password downtown2013-basic-auth true >/data/app/confd/config/$ Project_Name/confd_$project_name.log 2>&1 &echo "===============================" echo "[CONFD] for $Project _name Started "echo" =============================== "#启动app chmod 755/data/app/eshine/$Project _name/$Project _name chmod 755/data/app/eshine/$Project _name/*.py cd/data/app/eshine/$Project _name pwd Ps-ef | grep/data/app/eshine/$Project _name | Grep-v grep | awk ' {print ' kill-9 ' $ ' | Bash sleep nohup/data/app/eshine/$Project _name/$Project _name >>/data/logs/$Project _name.log 2>&1 & amp;} ###### #Deploy War done######### #Decide which script to being run by Project_name_suffixcase $Project _name_suffix in Ta        r.gz) Function_deploy_tar_gz;; *) echo ". tar.gz allowed only" Esacecho ====== scheduled Task ========crontab_add () {#根据系统定义crontab路径SYSTEM_OS = ' Lsb_relea Se-a |grep Description |awk-f: ' {print $} ' |sed ' s/^[\t]*//g ' echo ' "echo" = = = System_os is $SYSTEM _os==== "echo" "if [[$SYSTEM _os =~ Ubuntu]];thencrontab_file_for_root= "/var/spool/cron/crontabs/root" echo "====crontab Path is $CRONTAB _file_for_root" elsecrontab_file_for _root= "/var/spool/cron/root" echo "====crontab Path is $CRONTAB _file_for_root" fi# Add new croncd/data/app/eshine/$Project _nameif [-F crontab/time.txt];thensed-i '/python/d ' $CRONTAB _file_for_root sed-i/$Project _name/d $CRONTAB _file _for_rootcat./crontab/time.txt |egrep-v "^#|^$" >> $CRONTAB _file_for_rootsed-i '/PYTHON/S/PYTHON/CD \/data\/ App\/eshine\/menurank; python/' $CRONTAB _file_for_rootfi# immediately run the task if [-F crontab/once.txt];thenchmod 755 crontab/once.txt./crontab/ once.txtfi# View timed task status echo "################ system scheduled Task List start ################" Cat $CRONTAB _file_for_rootecho "########## ###### System Scheduled Task List end ################ "}crontab_dir=/data/app/eshine/$Project _name/crontabif [!-d" $Crontab _dir "]; Thenecho "###### #没有crontab目录 #######" Elsemain () {crontab_add}mainfiexit 0

 

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.