Advertisement
Guest User

safe_node_startup

a guest
Mar 4th, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Update SAFE_ROOT_DIR & SAFE_LOG_DIR before executing script
  2. # Assumes safe & sn_node are accessible and are part of your $PATH
  3.  
  4. function set_env_vars
  5. {  
  6.     [System.Environment]::SetEnvironmentVariable('NODES','15')
  7.     [System.Environment]::SetEnvironmentVariable('RUST_LOG','sn_node=info')
  8.     [System.Environment]::SetEnvironmentVariable('SAFE_ROOT_DIR','/mnt/remoteceph/safe_node_vault')
  9.     [System.Environment]::SetEnvironmentVariable('SAFE_LOG_DIR','/mnt/remoteceph/safe_node_json_logs')
  10.     [System.Environment]::SetEnvironmentVariable('TESTNET_NAME','local')
  11. }
  12.  
  13. function clean_up($nodes_count,$root_dir,$log_dir)
  14. {
  15.     if (Test-Path "$HOME/.safe/network_contacts")
  16.     {
  17.         Remove-Item "$HOME/.safe/network_contacts" -Recurse -Force
  18.     }
  19.  
  20.     Get-Process -Name sn_node -ErrorAction SilentlyContinue| Stop-Process -Force
  21.     Get-Process -Name safe -ErrorAction SilentlyContinue | Stop-Process -Force
  22.     for($i=1; $i -le $nodes_count; $i++)
  23.     {
  24.         if (test-path "$root_dir/node-$i")
  25.         {
  26.             Remove-Item "$root_dir/node-$i" -Recurse -Force
  27.         }
  28.         if (test-path "$log_dir/node-$i")
  29.         {
  30.             Remove-Item "$log_dir/node-$i" -Recurse -Force
  31.         }
  32.     }
  33. }
  34.  
  35. function init_network($nodes_count,$root_dir,$log_dir)
  36. {
  37.     #GENESIS NODE
  38.     New-Item -Path "$root_dir/node-1" -ItemType Directory
  39.     New-Item -Path "$log_dir/node-1" -ItemType Directory
  40.     sn_node -vvv --local-addr 127.0.0.1:0 --first 127.0.0.1:0 --root-dir $root_dir/node-1 --log-dir $log_dir/node-1 --json-logs &
  41.     Start-sleep -Seconds 1
  42.     for($i=2; $i -le $nodes_count; $i++)
  43.     {
  44.         New-Item -Path "$root_dir/node-$i" -ItemType Directory
  45.         New-Item -Path "$log_dir/node-$i" -ItemType Directory
  46.         sn_node -vvv --local-addr 127.0.0.1:0 --network-contacts-file $root_dir/node-1/section_tree --root-dir $config_dir/node-$i --log-dir $log_dir/node-$i --json-logs &
  47.         Start-Sleep -Seconds 1
  48.     }
  49. }
  50.  
  51. function check_network($testnet_name,$root_dir)
  52. {
  53.     safe networks
  54.     safe networks add local $root_dir/node-1/section_tree
  55.     safe networks switch $testnet_name
  56.     safe networks
  57.     safe networks check
  58.     safe networks sections $testnet_name
  59. }
  60.  
  61. set_env_vars
  62. clean_up $([System.Environment]::GetEnvironmentVariable('NODES')) $([System.Environment]::GetEnvironmentVariable('SAFE_ROOT_DIR')) $([System.Environment]::GetEnvironmentVariable('SAFE_LOG_DIR'))
  63. init_network $([System.Environment]::GetEnvironmentVariable('NODES')) $([System.Environment]::GetEnvironmentVariable('SAFE_ROOT_DIR')) $([System.Environment]::GetEnvironmentVariable('SAFE_LOG_DIR'))
  64. check_network $([System.Environment]::GetEnvironmentVariable('TESTNET_NAME')) $([System.Environment]::GetEnvironmentVariable('SAFE_ROOT_DIR'))
  65.  
  66. $userInput = read-host "Enter to exit"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement