BitShares Forum

Main => Stakeholder Proposals => Topic started by: alt on July 29, 2014, 01:20:30 am

Title: automatic restart tools (From BitSuperLab)
Post by: alt on July 29, 2014, 01:20:30 am
for now, delegate will miss blocks after long time running.
BM suggest to restart client every day.
here is a method for automatic restart.
1. run wallet with this expect script, you should change "wallet_name" and "command line"
this script will start client automatic while it's quit.
Code: [Select]
#!/usr/bin/expect -f

set timeout -1
set default_port 1776
set port $default_port

### change wallet_name here
set wallet_name "delegate"
send_user "wallet name is: $wallet_name\n"
send_user "wallet passphrase: "
stty -echo
expect_user -re "(.*)\n"
  stty echo
set wallet_pass $expect_out(1,string)

  proc run_wallet {} {
    global wallet_name wallet_pass default_port port
      ### change command line here
      spawn ./bitshares_client --data-dir=delegate --p2p-port $port --server --httpport 9989 --rpcuser user --rpcpassword pass

      expect -exact "(wallet closed) >>> "
      send -- "about\r"
      expect -exact "(wallet closed) >>> "
      send -- "wallet_open $wallet_name\r"
      expect -exact "$wallet_name (locked) >>> "
      send -- "wallet_unlock 99999999\r"
      expect -exact "passphrase: "
      send -- "$wallet_pass\r"
      expect -exact "$wallet_name (unlocked) >>> "
      send -- "wallet_delegate_set_block_production ALL true\r"
      expect -exact "$wallet_name (unlocked) >>> "
      send -- "info\r"
      expect -exact "$wallet_name (unlocked) >>> "
      send -- "wallet_list_my_accounts\r"
      interact
      wait

      if { $port == $default_port } {
        set port [expr $port+1]
      } else {
        set port [expr $port-1]
      }
  }

while true {
  run_wallet
}
2. kill the client every 24 hours.
call restart.py every 24 hours at crontab, this script will check next block generation timestamp, make sure there is enough time to restart client
Code: [Select]
#!/usr/bin/python

import requests
import json
import time
import os

safetime = 120  # safe time, 120 seconds is safe to restart client
auth = ('user', 'pass') ## user/pass for rpc service
url = "http://localhost:9989/rpc"  ## rpc url

def main() :
    headers = {'content-type': 'application/json'}
    info = {
        "method": "get_info",
        "params": [],
        "jsonrpc": "2.0",
        "id": 1
    }

    while True:
        info_res = requests.post(url, data=json.dumps(info), headers=headers, auth=auth)
        info_json = json.loads(vars(info_res)["_content"])
        if not "result" in info_json:
            return
        block_production_timestamp = info_json["result"]["wallet_next_block_production_timestamp"]
        safe_timestamp = time.strftime("%Y%m%dT%H%M%S", time.localtime(time.time()+safetime))
        if block_production_timestamp > safe_timestamp :
            break;
        #print("wait...")
        time.sleep(10)
    #print("kill...")
    time.sleep(10) ## wait 10 second make sure it's broadcast out
    os.system("killall -9 bitshares_client");

if __name__ == "__main__":
    main()
3. we'll provide more suitable tools to detect the missing block and restart automatic soon.
Title: Re: automatic restart tools (from DPOS super lab)
Post by: taoljj on July 29, 2014, 01:41:42 am
 +5%
Title: Re: automatic restart tools (from DPOS super lab)
Post by: HackFisher on July 29, 2014, 01:46:16 am
 +5% +5%
Title: Re: automatic restart tools (from DPOS super lab)
Post by: sfinder on July 29, 2014, 01:51:23 am
script needs to check "next block time" before restart. to be safe , "next block time" should be greater than 5 minutes
Title: Re: automatic restart tools (from DPOS super lab)
Post by: alt on July 29, 2014, 03:15:35 am
script needs to check "next block time" before restart. to be safe , "next block time" should be greater than 5 minutes
have updated at the 1  post
a python script will check this before kill the client
Title: Re: automatic restart tools (from DPOS super lab)
Post by: sfinder on July 29, 2014, 04:00:33 am
It would be nice if your script can  monitor connection number every 10minutes and alert with sendmail if connection drop to  less than 7
Title: Re: automatic restart tools (from DPOS super lab)
Post by: alt on July 29, 2014, 04:57:24 am
It would be nice if your script can  monitor connection number every 10minutes and alert with sendmail if connection drop to  less than 7
yes, we'll collect more information next step.
Title: Re: automatic restart tools (From BitSuperLab)
Post by: maqifrnswa on August 01, 2014, 03:20:11 am
excellent, thank you!
Title: Re: automatic restart tools (From BitSuperLab)
Post by: emski on August 01, 2014, 07:00:43 am
Good work!

You might instead of using the second script to kill the bitshares_client just to use "quit" within the first script (after you make sure info command returns "wallet_next_block_production_time": "X minutes in the future", where X is large enough for you).
Title: Re: automatic restart tools (From BitSuperLab)
Post by: Riverhead on August 08, 2014, 01:20:36 pm
Also, maybe include a wallet_delegate_withdraw_pay since the pass phrase for the delegate is stored on the server in plain text.  Would be good to keep that wallet swept.