diff --git a/.gitignore b/.gitignore index 62f53ef..7dc28eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,163 @@ -# ---> Java + +# Created by https://www.gitignore.io/api/java,vim,macos,linux,windows,intellij+all,microsoftoffice,maven,TortoiseGit,visualstudiocode,eclipse +# Edit at https://www.gitignore.io/?templates=java,vim,macos,linux,windows,intellij+all,microsoftoffice,maven,TortoiseGit,visualstudiocode,eclipse + +### Eclipse ### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +### Eclipse Patch ### +# Eclipse Core +.project + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Annotation Processing +.apt_generated + +.sts4-cache/ + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Java ### # Compiled class file *.class @@ -23,7 +182,7 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -# ---> Linux +### Linux ### *~ # temporary files which can be created if a process still has a handle open of a deleted file @@ -38,3 +197,131 @@ hs_err_pid* # .nfs files are created when an open file is removed but is still being accessed .nfs* +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +### MicrosoftOffice ### + +# Word temporary +~$*.doc* + +# Word Auto Backup File +Backup of *.doc* + +# Excel temporary +~$*.xls* + +# Excel Backup File +*.xlk + +# PowerPoint temporary +~$*.ppt* + +# Visio autosave temporary files +*.~vsd* + +### TortoiseGit ### +# Project-level settings +/.tgitconfig + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist + +# Auto-generated tag files +tags + +# Persistent undo +[._]*.un~ + +# Coc configuration directory +.vim + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/java,vim,macos,linux,windows,intellij+all,microsoftoffice,maven,TortoiseGit,visualstudiocode,eclipse +n \ No newline at end of file diff --git a/README.md b/README.md index 7fdbdfd..40a63ec 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # OpsDev -OpsDev \ No newline at end of file +## Screenshot + +![](./img/tty.gif) + diff --git a/img/tty.compress.gif b/img/tty.compress.gif new file mode 100644 index 0000000..68ea9c8 Binary files /dev/null and b/img/tty.compress.gif differ diff --git a/img/tty.gif b/img/tty.gif new file mode 100644 index 0000000..8c91b1d Binary files /dev/null and b/img/tty.gif differ diff --git a/script/load b/script/load new file mode 100755 index 0000000..ac2e0ee --- /dev/null +++ b/script/load @@ -0,0 +1,319 @@ +#!/usr/bin/env bash + +#===========================================# +# Author : Alawn # +# LastUpdated: 2020-04-08 # +# Dependency : bash, expect # +# Discription: Management Menu for NCBA MSL # +#===========================================# + +### Variables +cur_dir=$( pwd ) +base_usr=`whoami` +base_home=`cat /etc/passwd | grep $(whoami) | cut -d ':' -f 6` +usr_sh=`cat /etc/passwd | grep $(whoami) | cut -d ':' -f 7` +war_dir=${base_home}/apps/ +app_list=(`ls $war_dir | sed 's/\.war$//g'| sed 's/\-1\.0\-SNAPSHOT//g'`) +echo -e ${app_list[0]} +echo -e ${app_list[1]} +echo -e ${app_list[2]} +echo -e ${app_list[3]} +echo -e ${app_list[4]} +echo -e ${app_list[5]} +echo -e ${app_list[6]} +echo -e ${app_list[7]} +#exit +cur_app="" +app_num=${#app_list[@]} +myip=`hostname -I | sed 's/ //g'` +domain=`hostname|sed 's/ //g'` + +### User define +conf_common_dataid="common.properties" +conf_group="DEFAULT_GROUP" +conf_directory="/home/ncbamsl/conf/" +conf_center_host="10.0.0.13:9084" +profile_common="common.properties" +startup_script="${base_home}/bin/startApp-configclient.sh" +inject_script=${base_home}/.inject.script +initrc=${base_home}/.injectrc + +### Constants +red='\033[0;31m' +green='\033[0;32m' +yellow='\033[0;33m' +blue='\033[36m' +gray='\033[37m' +plain='\033[0m' + +declare -A module_map=() + +module_map["gateway-openapi"]="ogw" +module_map["manage-openapi"]="oam" +module_map["gateway-external"]="egw" +module_map["gateway-internal"]="igw" +module_map["industry-application"]="ias" +module_map["customer"]="urm" +module_map["customer-campaign"]="ccs" +module_map["savings"]="sas" +module_map["savings-service"]="sas" +module_map["loan-service"]="lns" +module_map["loan-account"]="lon" +module_map["wallet-service"]="wls" +module_map["account"]="acm" +module_map["accounting"]="act" +module_map["basic-service"]="bap" +module_map["product"]="prd" +module_map["boss"]="bui" +module_map["batch"]="bat" +module_map["data-feed"]="dfs" +module_map["ecp-message"]="ems" +module_map["ecp-message-app"]="msc" +module_map["notification-center"]="ntc" +module_map["ecp-ops"]="ops" + + +### Function +main_menu() +{ + while true + do + title=" Please Enter Your Application:[1-$app_num]" + clear + echo -e + echo -e "${blue}NCBA MSL Management Menu (RWA)${plain}" + echo -e "----------------------------------------------" + echo -e $title + echo -e "----------------------------------------------" + echo -e "" + + ## render app menu + for ((i=1;i<=${#app_list[@]};i++ )); do + hint="${app_list[$i-1]}" + state=`get_app_state ${hint}` + printf "${green}%-4s${plain} %-30s [$([ "$state" == "running" ] && echo ${green} || echo ${red})%-7s${plain}]\n" ${i}")" ${hint} ${state} + done + + ## Ask user which choice and press key + echo -e "" && read -p "Please enter a number:" selected + case "${selected}" in + [1-9]*) + if [ "${selected}" -gt $app_num ]; then + title="[${red}Error${plain}] Please only enter a number [1-$app_num]" + continue + fi + echo + echo "You choose = ${app_list[${selected}-1]}" + cur_app=${app_list[${selected}-1]} + echo + function_menu + ;; + q) + exit 0 + ;; + a) + clear + for ((j=1;j<=${#app_list[@]};j++ )); do + hint="${app_list[$j-1]}" + echo -e "${green}${j}${plain}) ${hint} status" + done + echo -e && read -s -n1 -p "Press any key go back" + ;; + *) + + title="[${red}Error${plain}] Please only enter a number [1-$app_num]" + ;; + esac + done +} + +create_initrc() +{ + if [ ! -f ${initrc} ]; then + cat > ${initrc} < ${inject_script} +spawn /usr/bin/env ${usr_sh} +send ". ${initrc}\n" +interact +EOF + fi + +} + +inject() +{ + ## Define environment variable and it can be inherited into sub shell + export HOME=${base_home}/${cur_app} + export HWORKDIR=$HOME + export LOGNAME=$cur_app + + ## Create RC file if it not exists + create_initrc + + ## Create expect script if it not exists + create_inject_script + + ## Execute expect script for app as interact mode + expect ${inject_script} + + ## Recover $HOME environment after sub shell has been logout + export HOME=${base_home} +} + + +function_menu() +{ + #title=" Please Enter Your Operation:[1-4]" + while true + do + pid=`get_app_pid ${cur_app}` + state=`get_app_state ${cur_app}` + + if [ "running" == "$state" ]; then + title="$cur_app is [${green}running($pid)${plain}] " + else + title="$cur_app is [${red}dead${plain}]" + fi + + clear + echo -e "----------------------------------------------" + echo -e $title + echo -e "----------------------------------------------" + echo -e "" + echo -e "${green}1${plain}) Startup/Restart" + echo -e "${green}2${plain}) Shutdown" + echo -e "${green}3${plain}) Login" + echo -e "" + echo -e "${green}b${plain}) Go back" + echo -e "" + + echo -e && read -p "Please enter a number :" selected + [ -z "${selected}" ] && selected="status" + case "${selected}" in + 1) + ## Startup Application + module_name=${module_map["${cur_app}"]} + profile_app="" + + if [ "" != "$module_name" ]; then + profile_app=${module_name}.properties + else + profile_app=${profile_common} + fi + + + node_id=${module_name}_${domain} + cmd="${startup_script} ${cur_app} -serverAddr ${conf_center_host} -appDataId ${profile_app} -commonDataId ${profile_common} -group ${conf_group} -filedir ${conf_directory}${moddule_name}/ -nodeId ${node_id}" + #echo ${cmd} + clear + echo -e "" + echo -e "${blue}>> Now prepare startup application, please wait a moment...${plain}" + sh ${cmd} + #exit 0 + + echo -e "" && read -s -n1 -p "Press any key continue..." + break + ;; + 2) + ## Stop application + clear + echo -e "" + echo -e "${blue}>> Now beginning kill the application with PID:${pid}...${plain}" + echo -e "" + + if [ "${pid}" != "" ]; then + + kill -9 ${pid} + + sleep 1 + + state=get_app_state + + [ "${state}" == "running" ] && echo -e "${red}Application not been kill...${plain}" || echo -e "${green}Application has been killed...${plain}" + + else + echo -e "${yellow}Application is not running...${plain}" + fi + + echo -e "" && read -s -n1 -p "Press any key continue..." + + break + ;; + 3) + ## Login as application user + echo -e "${green}1${plain}) 进入系统" + inject + break + ;; + b|q) + break + ;; + *) + ## Echo error message when other key pressed + title="[${red}Error${plain}] Please only enter a number [1-4]" + ;; + esac + done +} + + +get_app_state() +{ + app=$1 + pid=`ps -ef | grep "/${app}.war" | grep -v grep|awk '{print $2}'` + echo $([ ! -z "${pid}" ] && echo "running" || echo "dead") + return 0 +} + +get_app_pid() +{ + app=$1 + echo $(ps -ef | grep "/${app}.war" | grep -v grep|awk '{print $2}') + return 0 +} + +main_menu +exit 0