(07-12-2016 05:54 PM)YU_Xinjie Wrote: goal
1. the script can be used in both sage_portal & glad_portal to start/stop/status sage.
2. user can start sage before glad, and stop sage after glad.
The script would replace the current start.sh/stop.sh/status.sh in the future.
The script may inspire us about how to set up regression tests for sage.
For shbio's project, I have already written a script /thinker/dstore/run/sage to support a part of the goal. I would try to generalize it.
config design
The brief idea is to use auntie to send a file to glad_portal. Then check the file content.
1.
require sage_user can password-less login sage_user@sage_portal
copy private key of sage_user@sage_portal into $gb/conf/sage_key
But SSH command would check the premission of private key. If the key can readable by others, SSH would just ignore the key. One method to skip the check is to set the owner of key to be a user that would never use the key. For example:
Code:
[0][15:40:42] xinjie@devmac0e0:/thinker/dstore/gene/glad/conf
$ ll sage_key
-rw-r--r--. 1 dstore dstore 1679 Sep 8 14:57 sage_key
I set the owner to be dstore. Then user gene, sage, xinjie can use the key to access sage_portal. Only user dstore can not do that.
Then glad operative user & sage_user can use sage_key to execute remote command to sage_user@sage_portal.
2. The glad_portal IP can be get from $gb/conf/config.sh
3.
create a config file $gb/conf/sage_portal_ip to record the IP of sage_portal. Or we can also write it into $gb/conf/config.sh.
4. let sage_user@sage_portal can password-less login glad_user@glad_portal.
start sage
Code:
wait_sage_start () {
content="This is test content."
echo $content > $curdir/${USER}_sage_testfile
test_file=/thinker/bin/ephemeral/667.sagetest
# 30 seconds timeout
try_cnt=10
while [[ ("$try_cnt" -gt "0") && ((! -f "$test_file") || ("$(cat $test_file)" != "$content")) ]]; do
timeout -s SIGINT 1 bash -c "sage_user=$sage_user $curdir/auntie ^$curdir/${USER}_sage_testfile $glad_portal 667 sagetest" || echo -n ''
echo "Trying to start Sage..."
sleep 2
try_cnt=$((try_cnt-1))
done
rm -f $test_file
if [[ "$try_cnt" == "0" ]];then
# timeout
return 1
else
return 0
fi
}
start_sage () {
# check whether sage is really stopped.
local tmp="$(status_sage)"
if [[ "$tmp" != "Sage is stopped." ]]; then
echo "Sage is already started."
echo ""
echo "Status: "
echo "$tmp"
return 0
fi
remote_cmd "screen -dmS sage_service bash -c 'cd ~/sage; ./start.sh'"
local rt="succ"
wait_sage_start || rt="fail"
if [[ "$rt" == "succ" ]]; then
echo "Sage is started."
else
echo "Sage fails to start."
fi
}
stop sage
Code:
stop_sage () {
# stop sage
remote_cmd "cd ~/sage; ./stop.sh" > /dev/null
# kill all sage_service screens
remote_cmd "
for session in \$(screen -ls | grep 'sage_service' | grep -o '[0-9]\+\.' | grep -o '[0-9]\+')
do
screen -S \${session} -p 0 -X quit
done
"
# check whether sage is really stopped.
local tmp="$(status_sage)"
if [[ "$tmp" == "Sage is stopped." ]]; then
echo "Sage is stopped."
else
echo "Sage failed to stop."
echo ""
echo "Status: "
echo "$tmp"
fi
}
status sage
Code:
status_sage () {
local output="$(remote_cmd "cd ~/sage; ./status.sh")"
if [[ "$output" == "Sage is stopped." ]]; then
echo "Sage is stopped."
else
echo "$output"
fi
}
Save a copy before changing.