Change the startup delay of node processes using an automated script - SkycoinProject/skywire GitHub Wiki

skywire logo

Change the startup delay of node processes using an automated script

This guide assumes that you have read and understood the readme.md, downloaded the official images or installed Skywire from source and do every step exactly the way it is described. Misconduct will lead to an inability to connect and to potential reflashing. It is very important that there is no IP collision with your existing home router subnet. The default settings of the official images, as well as the router of the Skyminer, are using the 192.168.0.0/24 subnet.

Table of Contents


Introduction

This guide will enable you to deploy a script which changes the delay time of the secondary nodes, so that you don't have to wait a certain amount of time between turning the pi's on. All the steps are designed for usage with the official images but can be adjusted to work with any other startup scripts as well.

Requirements

  • official images/multiple pi's with static ip's
  • SSH/Putty to access the manager pi or access to the manager's web interface

Usage

Create the script

Login to your manager pi via SSH/using putty or open a terminal inside the manager's web interface.

Change to home directory via cd ~. Now we need to create the script that will take care of the changes we want to apply.

Execute nano add_timedelay.sh to open an editor:

This is the content of the script that we are going to use. Copy and paste it into the editor you just opened.

#!/bin/bash
#This script changes the delay before th node process gets executed on the 
#the secondary pi's. It is useful to enable concurrent booting of the pis.

#increasing time delay
delay=20

USERNAME=root
#list of IP address of the secondary pi's
HOSTS="192.168.0.3 192.168.0.4 192.168.0.5 192.168.0.6 192.168.0.7 192.168.0.8 192.168.0.9"
#change time delay
for HOSTNAME in ${HOSTS} ; do
    if ping -W5 -i0.5 -c 1 &> /dev/null
    then
        echo 1
        echo "no connection to host" ${HOSTNAME}
    else
        echo "ping received from" ${HOSTNAME}
        ssh ${USERNAME}@${HOSTNAME} "sed -i 's/sleep.*/sleep $delay/' /etc/rebuild.sh"
        delay=`expr $delay + 10`
	echo "Changed delay of ${HOSTNAME} to $delay"
    fi
done

Save the file via ctrl+x and yes.

After that make the script executable via chmod +x add_timedelay.sh

Execute the script

Execute the script via ./add_timedelay.sh, you will be queried to enter the passwords for the root user one after another. The output should look like this:

executed

Note: The script outputs the modified delay for each node it connected to 'Changed delay of 192.168.0.3 to 20'.


Troubleshooting

Unable to connect to pi

If you happen to encounter the error message Read from socket failed: connection reset by peer

then you need need to apply the steps describe here

Adjustments

Adjust the script to work with other IPs

If the location of the .skywire folders is the same and you are also using root as a user then you only have to change the following line:

HOSTS="192.168.0.3 192.168.0.4 192.168.0.5 192.168.0.6 192.168.0.7 192.168.0.8 192.168.0.9"

to

HOSTS="IP_NODE_1 IP_NODE_2 IP_NODE_3 IP_NODE_4 IP_NODE_5 IP_NODE_6 IP_NODE_7 IP_NODE_8 IP_NODE_9"

where you have to replace IP_NODE_1 IP_NODE_2 etc. with the IPs of your nodes.

Keep in mind that the IPs are starting with your first node and not with the IP of the manager!

Different location + content of the startup script

If the location of the startup scripts are unknown, then you have to change the following line to the location of your startup scripts. If you followed a guide read up in there to find out the location of the startup script(s) you're using.

ssh ${USERNAME}@${HOSTNAME} "sed -i 's/sleep.*/sleep $delay/' /location/of/your/startup/script"

to the location of your startup script.

You need to check the content of your startup script to find out whether or not the default values will work in your case.

The replacement command is looking for a line starting with sleep followed by anything. If your startup script implements the time delay in another way and your script does not contain a line starting with sleep you have to adjust the sed -i 's/sleep.*/sleep $delay/' ... command accordingly.

Different user than root

If you can't login via root user, because you're using raspbian for example or decided to install Skywire as another user you need to change the following line in the script:

USERNAME = your_username

to the user you are using on the pi's.