Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Service management of Sage - D
09-27-2016, 05:16 PM
Post: #25
RE: Service management of Sage
(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.
Quote this message in a reply
Post Reply 


Messages In This Thread
Service management of Sage - D - YU_Xinjie - 07-12-2016, 05:54 PM
RE: Service management of Sage - YU_Xinjie - 09-07-2016, 02:00 PM
RE: Service management of Sage - YU_Xinjie - 09-07-2016, 02:47 PM
RE: Service management of Sage - lingu - 09-07-2016, 03:53 PM
RE: Service management of Sage - YU_Xinjie - 09-07-2016, 04:11 PM
RE: Service management of Sage - lingu - 09-07-2016, 05:06 PM
RE: Service management of Sage - YU_Xinjie - 09-07-2016, 05:18 PM
RE: Service management of Sage - lingu - 09-07-2016, 03:55 PM
RE: Service management of Sage - lingu - 09-07-2016, 03:58 PM
RE: Service management of Sage - lingu - 09-07-2016, 05:35 PM
RE: Service management of Sage - YU_Xinjie - 09-07-2016, 05:53 PM
RE: Service management of Sage - lingu - 09-07-2016, 06:18 PM
RE: Service management of Sage - YU_Xinjie - 09-07-2016, 06:37 PM
RE: Service management of Sage - lingu - 09-07-2016, 06:53 PM
RE: Service management of Sage - YU_Xinjie - 09-08-2016, 04:28 PM
RE: Service management of Sage - lingu - 09-15-2016, 12:49 AM
RE: Service management of Sage - lingu - 09-07-2016, 06:52 PM
RE: Service management of Sage - YU_Xinjie - 09-08-2016, 04:48 PM
RE: Service management of Sage - lingu - 09-15-2016, 12:34 AM
RE: Service management of Sage - YU_Xinjie - 09-18-2016, 03:59 PM
RE: Service management of Sage - lingu - 09-23-2016, 10:41 PM
RE: Service management of Sage - YU_Xinjie - 09-27-2016, 11:33 AM
RE: Service management of Sage - lingu - 09-27-2016, 12:35 PM
RE: Service management of Sage - YU_Xinjie - 09-08-2016, 06:41 PM
RE: Service management of Sage - YU_Xinjie - 09-27-2016 05:16 PM
RE: Service management of Sage - YU_Xinjie - 09-27-2016, 05:34 PM
RE: Service management of Sage - OMUD - YU_Xinjie - 10-19-2016, 06:37 PM
RE: Service management of Sage - OMUD - YU_Xinjie - 12-06-2016, 12:32 PM
RE: Service management of Sage - OMUD - YU_Xinjie - 12-06-2016, 03:32 PM
RE: Service management of Sage - OMUD - YU_Xinjie - 01-12-2017, 07:05 PM
RE: Service management of Sage - OD - YU_Xinjie - 06-02-2017, 06:24 PM
RE: Service management of Sage - D - lingu - 05-08-2019, 09:55 PM
RE: Service management of Sage - D - lingu - 05-08-2019, 10:01 PM
RE: Service management of Sage - D - xwcwt - 05-09-2019, 10:37 AM
RE: Service management of Sage - D - lingu - 05-09-2019, 06:39 PM
RE: Service management of Sage - D - lingu - 05-09-2019, 06:42 PM
RE: Service management of Sage - D - lingu - 05-09-2019, 06:52 PM
RE: Service management of Sage - D - lingu - 05-09-2019, 07:09 PM
RE: Service management of Sage - D - xwcwt - 05-09-2019, 07:12 PM
RE: Service management of Sage - D - lingu - 05-10-2019, 07:41 PM
RE: Service management of Sage - D - lingu - 05-10-2019, 07:46 PM
RE: Service management of Sage - D - xwcwt - 05-11-2019, 10:14 AM
RE: Service management of Sage - D - lingu - 05-10-2019, 07:56 PM
RE: Service management of Sage - D - lingu - 11-23-2019, 11:48 PM
RE: Service management of Sage - D - zheny - 11-24-2019, 06:09 PM
RE: Service management of Sage - D - xwcwt - 11-25-2019, 03:17 PM
RE: Service management of Sage - D - lingu - 11-23-2019, 11:30 PM

Forum Jump: