Optimize code; Make inject script temporay; New feature about 'Trace Logging'

This commit is contained in:
2020-04-09 16:29:22 +08:00
parent 592e27a977
commit 5f23325fac
+42 -27
View File
@@ -127,7 +127,7 @@ main_menu()
done
}
create_initrc()
initrc()
{
if [ ! -f ${initrc} ]; then
cat > ${initrc} <<EOF
@@ -171,34 +171,39 @@ EOF
}
create_inject_script()
{
if [ ! -f ${inject_script} ]; then
cat <<EOF > ${inject_script}
spawn /usr/bin/env ${usr_sh}
send ". ${initrc}\n"
interact
EOF
fi
}
inject()
{
cmd=$*
## 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
initrc
## Create expect script if it not exists
create_inject_script
## Create expect script temporary
script=`mktemp`
cat <<EOF > ${script}
spawn /usr/bin/env ${usr_sh} --norc
send ". ${initrc}\n"
EOF
if [ $# -ge 1 ]; then
cat <<EOF >> ${script}
send "source <(cat <<OOF\n${cmd};exit 0\nOOF\n)\n"
EOF
fi
cat <<EOF >> ${script}
interact
EOF
## Execute expect script for app as interact mode
expect ${inject_script}
expect ${script}
## Recover $HOME environment after sub shell has been logout
export HOME=${base_home}
}
@@ -223,9 +228,10 @@ function_menu()
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 "${green}1${plain}) Login"
echo -e "${green}2${plain}) Startup/Restart"
echo -e "${green}3${plain}) Shutdown"
echo -e "${green}4${plain}) Trace Logging"
echo -e ""
echo -e "${green}b${plain}) Go back"
echo -e ""
@@ -234,6 +240,12 @@ function_menu()
[ -z "${selected}" ] && selected="status"
case "${selected}" in
1)
## Login as application user
echo -e "${green}1${plain}) 进入系统"
inject
break
;;
2)
## Startup Application
module_name=${module_map["${cur_app}"]}
profile_app=""
@@ -257,8 +269,8 @@ function_menu()
echo -e "" && read -s -n1 -p "Press any key continue..."
break
;;
2)
## Stop application
3)
## Shutdown application
clear
echo -e ""
echo -e "${blue}>> Now beginning kill the application with PID:${pid}...${plain}"
@@ -282,10 +294,13 @@ function_menu()
break
;;
3)
## Login as application user
echo -e "${green}1${plain}) 进入系统"
inject
4)
## Trace logging
echo -e "${blue}>> Trace logging...${plain}"
echo -e ""
#tail -f ${base_home}/${cur_app}/log/${cur_app}.out
cmd="tail -f ${base_home}/${cur_app}/log/${cur_app}.out"
inject ${cmd}
break
;;
b|q)