Author Topic: automatic restart tools (From BitSuperLab)  (Read 3843 times)

0 Members and 1 Guest are viewing this topic.

Offline Riverhead

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.

Offline emski

  • Hero Member
  • *****
  • Posts: 1282
    • View Profile
    • http://lnkd.in/nPbhxG
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 maqifrnswa

  • Hero Member
  • *****
  • Posts: 661
    • View Profile
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 alt

  • Hero Member
  • *****
  • Posts: 2821
    • View Profile
  • BitShares: baozi
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 sfinder

  • Hero Member
  • *****
  • Posts: 1205
  • 4 Cores CPU+100GB SSD+anti-DDoS Pro
    • View Profile
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

  • Hero Member
  • *****
  • Posts: 2821
    • View Profile
  • BitShares: baozi
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
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 HackFisher

  • Hero Member
  • *****
  • Posts: 883
    • View Profile
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 taoljj

  • Full Member
  • ***
  • Posts: 177
    • View Profile
BTS      Witness: delegate.taoljj

Offline alt

  • Hero Member
  • *****
  • Posts: 2821
    • View Profile
  • BitShares: baozi
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 »