fragamemnon

BOINC_scriptgenerator

Apr 27th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.82 KB | None | 0 0
  1. #!/bin/bash
  2. # This script assumes that your username is boinc. Feel free to use ~/ or replace it with your current/desired username.
  3. # Initiate two counter files:
  4. echo 0 > /home/boinc/counter
  5. echo 0 > /home/boinc/counter2
  6. # Create one directory to contain all the boinc datadirs, for cleanliness:
  7. mkdir /home/boinc/datafiles
  8. # Create a password which you will use for remote administration:
  9. echo "mypassword" > /home/boinc/datafiles/gui_rpc_auth.cfg
  10. # Allow the IP from which you will have access to these machines:
  11. echo "ip_of_the_machine_running_BoincTasks" > /home/boinc/datafiles/remote_hosts.cfg
  12. # If you want access from more than one computer, uncomment the second line and copy it (not the one above!):
  13. #echo "ip_of_the_second_machine_running_BoincTasks" >> /home/boinc/datafiles/remote_hosts.cfg
  14. # Create the scripts which we will later use:
  15. echo "#!/bin/bash" > /home/boinc/client_run.sh
  16. echo "#!/bin/bash" > /home/boinc/project_attach.sh
  17. echo "#!/bin/bash" > /home/boinc/project_update.sh
  18. # Each running instance will need a different port. That is one of the reasons for the counter. However, since ports 1-1024 are reserved and we often have other ports bound to specific software, this will allow you to set a starting port for the running clients in order to avoid conflicts:
  19. portIncrement=30000
  20. # Create a simple loop which will iterate for as many times as the number of clients you want running (in this case 240):
  21. while [ `cat /home/boinc/counter` -lt 240 ]; do {
  22.         # First, read the counter:
  23.         counter=`cat /home/boinc/counter`
  24.         # The first client is 1, so we add 1 to the counter:
  25.         let countNew=$counter+1
  26.         # Create a variable which will take the port and offset it with the value of the variable we declared above:
  27.         let port=$countNew+$portIncrement
  28.         # Create the datadir for the current client (this will result in boincdata1, boincdata2 ...). I choose to name the folder zdatadirs so it shows last when I ls the contents of the folder.
  29.         mkdir /home/boinc/zdatadirs/boincdata$countNew
  30.         # Copy the authentication and host whitelist files into the newly created directory:
  31.         cp /home/boinc/datafiles/gui_rpc_auth.cfg /home/boinc/zdatadirs/boincdata$countNew/
  32.         cp /home/boinc/datafiles/remote_hosts.cfg /home/boinc/zdatadirs/boincdata$countNew/
  33.         # Create the run command for this specific instance. The example shows the command line I use:
  34.         echo "boinc --allow_multiple_clients --allow_remote_gui_rpc --gui_rpc_port $port --daemon --dir /home/boinc/zdatadirs/boincdata$countNew --no_gpus --suppress_net_info" >> /home/boinc/client_run.sh
  35.         # Add some dialogue so you are aware what's happening once you run the client_run script:
  36.         echo "echo Started client $countNew/240. Sleeping for 0 seconds..." >> /home/boinc/client_run.sh
  37.         # If you want to start the clients gently, uncomment the following line and modify the echo above to reflect the delay (in seconds) between launching of the instances:
  38.         #echo "sleep 3" >> /home/boinc/client_run.sh
  39.         # Otherwise, a delay of 0 works fine.
  40.         # Create the script which will connect to each running client via boinccmd and attach it to a certain project:
  41.         echo "boinccmd --host the_machine_or_VMs_IP:$port --passwd mypassword --project_attach http://url.of.the.proj.ect/ FULL_CONTROL_PASSKEY" >> /home/boinc/project_attach.sh
  42.         # Create a dialogue. I recommend adding a delay here because the burst in open connections and network communications can cause the server to reject you for some time, or, well, bring your router down. :)
  43.         echo "echo Attached $countNew/240 to project. Sleeping for 15 seconds..." >> /home/boinc/project_attach.sh
  44.         echo "sleep 15" >> /home/boinc/project_attach.sh
  45.         # Now, this xmlconfig contains all the XML data you need to add to your BoincTasks's computers.xml file in order to see them. This is a workaround for having to add every single one manually. I recommend connecting to one client with the same password you've chosen in order to see it parsed, then paste the string below. Otherwise you will not be able to connect to your clients. The id_name tag defines how the computer will be seen in your BoincTasks window, so pick any name you wish.
  46.         cat <<EOF >> /home/boinc/xmlconfig
  47. <computer>
  48.     <id_name>BOINC240-$countNew</id_name>
  49.     <id_group></id_group>
  50.     <ip>`hostname -I`</ip>
  51.     <mac></mac>
  52.     <checked>1</checked>
  53.     <port>$port</port>
  54.     <password>%-something%-%something%%-%something-1</password>
  55. </computer>
  56. EOF
  57. # Update the counter, and close the loop.
  58. echo $countNew > /home/boinc/counter
  59. }
  60. done
  61. #>>>>>ADDING PROJECT_UPDATE<<<<<
  62. # Now we use the second counter which will allow us to run two scripts at the same time (project_attach and project_update):
  63. while [ `cat /home/boinc/counter2` -lt 240 ]; do {
  64. count2=`cat /home/boinc/counter2`
  65. let count2New=$count2+1
  66. let port2=$count2New+$portIncrement
  67. cat <<EOF >> /home/boinc/project_update.sh
  68. boinccmd --host the_machine_or_VMs_IP:$port2 --passwd mypassword --project http://url.of.the.proj.ect/ update
  69. echo "Updated project on client $count2New/240. Sleeping for 15 seconds..."
  70. sleep 15
  71. EOF
  72. echo $count2New > /home/boinc/counter2
  73. }
  74. done
  75. #>>>>>END OF PROJECT_UPDATE<<<<<
  76.  
  77. # Finally, mark our newly created scripts as executable:
  78. chmod +x /home/boinc/client_run.sh
  79. chmod +x /home/boinc/project_attach.sh
  80. chmod +x /home/boinc/project_update.sh
  81.  
  82. # If you want to automatically create all these scripts AND run them (simultaneously, in the total timespan of 3630s /1h, 0m, 30s/), uncomment the following lines:
  83. #echo "Running scripts..."
  84. sh /home/boinc/client_run.sh
  85. sleep 10
  86. echo "Attaching projects in the background..."
  87. sh /home/boinc/project_attach.sh &
  88. sleep 30
  89. echo "Now starting to update the projects... This runs with a 30 seconds delay from the attached clients."
  90. sh /home/boinc/project_update.sh
Add Comment
Please, Sign In to add comment