Author [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] Topic: automatic restart tools (From BitSuperLab)  (Read 764 times)

0 Members and 1 Guest are viewing this topic.

Offline alt

automatic restart tools (From BitSuperLab)
« 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.
« Last Edit: July 30, 2014, 05:35:19 AM by alt »

Offline taoljj

  • Full Member
  • ***
  • Posts: 175
    • View Profile
Re: automatic restart tools (from DPOS super lab)
« Reply #1 on: July 29, 2014, 01:41:42 AM »
 +5%
BTS      Witness: delegate.taoljj

Offline HackFisher

  • Hero Member
  • *****
  • Posts: 883
    • View Profile
Re: automatic restart tools (from DPOS super lab)
« Reply #2 on: July 29, 2014, 01:46:16 AM »
 +5% +5%
Anything said on these forums does not constitute an intent to create a legal obligation or contract between myself and anyone else.   These are merely my opinions and I reserve the right to change them at any time.

Offline sfinder

  • Hero Member
  • *****
  • Posts: 1205
  • 4 Cores CPU+100GB SSD+anti-DDoS Pro
    • View Profile
Re: automatic restart tools (from DPOS super lab)
« Reply #3 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
微博:星在飘我在找|BTS X 受托人delegate ID:baidu
中国教育书店合作将20%收入捐献给贫困山区学生。
Cooperating with China Education Bookstore and will donate 20% of delegate income to the poor students

Offline alt

Re: automatic restart tools (from DPOS super lab)
« Reply #4 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

Offline sfinder

  • Hero Member
  • *****
  • Posts: 1205
  • 4 Cores CPU+100GB SSD+anti-DDoS Pro
    • View Profile
Re: automatic restart tools (from DPOS super lab)
« Reply #5 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
微博:星在飘我在找|BTS X 受托人delegate ID:baidu
中国教育书店合作将20%收入捐献给贫困山区学生。
Cooperating with China Education Bookstore and will donate 20% of delegate income to the poor students

Offline alt

Re: automatic restart tools (from DPOS super lab)
« Reply #6 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.

Offline maqifrnswa

  • Hero Member
  • *****
  • Posts: 661
    • View Profile
Re: automatic restart tools (From BitSuperLab)
« Reply #7 on: August 01, 2014, 03:20:11 AM »
excellent, thank you!
maintains an Ubuntu PPA: https://launchpad.net/~showard314/+archive/ubuntu/bitshares [15% delegate] wallet_account_set_approval maqifrnswa true [50% delegate] wallet_account_set_approval delegate1.maqifrnswa true

Offline emski

  • Hero Member
  • *****
  • Posts: 1283
    • View Profile
    • http://lnkd.in/nPbhxG
Re: automatic restart tools (From BitSuperLab)
« Reply #8 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).

Offline Riverhead

Re: automatic restart tools (From BitSuperLab)
« Reply #9 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.

 

Google+