A solution for the disappearing node app key in Skywire Manager with autostart scripts for your DIY Skyminer on Raspberry Pi and Pine64 Rock64 — Difficulty level: 3/5

Ronny
4 min readJun 11, 2018

--

If your node app is running automatically, no need to read further. This article is not for you. But If you are having problems starting the node app automatically on boot, maybe this article is for you.

Summary

In this article I describe how I am able to use autostart scripts with the correct public address and the node app running automatically.

The key of the node application. If you see this: Congrats! If you do not see it, check out my solution.

The problem

When you install Skywire according to https://downloads.skycoin.net/skywire/Skywire-Installation-Guide-v1.0.pdf, you probably installed it as user pi on a Raspberry Pi and/or user rock64 on a rock64.

When running auto-startup scripts, these scripts are executed by user root. Therefore user root is looking for the folder go and the hidden folder .skywire under /root. But these folders are in the /home/pi/ or /home/rock64 folder. To solve this problem, you can copy these 2 folders to /root.

The solution

cd to the root of the current user that is logged in.

cd ~

Find hidden .skywire folders

Now we need to find all .skywire folders on the pi and select the correct one for auto startup in the future.

Please note that in this example, rock64 is the user that installed Skywire in the past. If you are on Raspberry Pi, the default user is pi. Replace rock64 -> pi

find / -name .skywire 2> /dev/null

In my case the result was:
/home/rock64/.skywire
/home/rock64/go/bin/.skywire

Find the .skywire folder that was used in the past

Now we need to check which .skywire folder has got the keys that we registered:

sudo nano /home/rock64/go/bin/.skywire/node/keys.json
sudo nano /home/rock64/.skywire/node/keys.json

It turned out that the keys used to register my miner for testnet, were in the folder:

/home/rock64/go/bin/.skywire/node/keys.json

Backup to be safe

So first I want to backup this folder. I login as root:

sudo -i

Now I make a copy of this folder:

cp -r /home/rock64/go/bin/.skywire
/home/rock64/go/bin/.skywireMyBACKUP
#check it, -a shows hidden folders & files:
ls /home/rock64/go/bin/ -a

Building /root

Now let’s see what is in /root:

ls /root

Empty? → Time to copy!

cp -r /home/rock64/go/bin/.skywire /root/.skywire
cp -r /home/rock64/go /root/go

Fix go for root

Now we need to fix go for the root user. We are still logged in as root (sudo -i) and we go to:

cd ~
nano .bashrc

Edit the file and put this at the end:

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

Safe the file (ctrl X and Y)

Run this to load:

source ~/.bashrc

Fix startup scripts for root

Now we are going to make a new startup script. First we generate it. For example generate it in /etc/init.d/

cd /etc/init.d
nano Startupscript.sh

The code:

#!/bin/sh
export GOPATH=$HOME/go
cd $GOPATH/bin
./manager -web-dir /root/go/src/github.com/skycoin/skywire/static/skywire-manager > /dev/null 2>&1 &
echo "Skywire is now running in the background. You can now access the Skywire Manager via the web browser"
sleep 5
cd $GOPATH/bin
./node -connect-manager -manager-address :5998 -manager-web :8000 -discovery-address testnet.skywire.skycoin.com:5999-028ec969bdeb92a1991bb19c948645ac8150468a6919113061899051409de3f243 -address :5000 -web-port :6001 &> /dev/null 2>&1 &
echo "Skywire monitor started."
echo "You can now open the monitor in your browser: http://#.#.#.#:8000"
sleep 10

Ctrl X and Y to safe.

Note: if your manager is running on another pi, edit manager-address and manager-web.

Adjust permissions of the Startupscript.sh

Adjust permissions:

cd /etc/init.d
chmod 755 Startupscript.sh

Test the script:

cd /etc/init.d
./Startupscript.sh

No errors?

reboot

Final step -> code for auto-boot

Add a line of code to crontab so Startupscript.sh will automatically run on boot:

sudo -i
cd /etc
crontab -e
#add this code at the end:
@reboot /etc/init.d/Startupscript.sh

Reboot

reboot

Please note that if you used any startup service in the past (check the name, and replace yourstartupservice with the name you used for all your nodes and manager), disable them:

systemctl disable yourstartupservice.service

That’s it.

Disclaimer and Warning

This solution is without any warranties and I am not responsible for anything. This article is only for education purposes. If you use this code, you use it at your own risk. I am not a team member, therefore this is not an official solution.

Always test your code on a spare pi with a spare sd card BEFORE you put it into production or use it!

Some handy commands

#Change password
passwd
#set timezone
sudo timedatectl status
sudo timedatectl list-timezones
sudo timedatectl set-timezone ###timezone#####
#check log
sudo tail -f /var/log/syslog
#show hidden folders, like .skywire
ls -a
#login as root
sudo -i
#shutdown
sudo shutdown -h now
#find out if you app node is running
ps aux | grep ‘node’ | awk ‘{print $2, $11}’
#check log
journalctl -xe
#remove executable rights
sudo chmod 644
#check permissions
ls -l

Cheers!
Ronny

SKYCOIN: 2FBZoLvKQsySAzSz3RV1ve62iRTMjvf9vge
BITCOIN: 16VynXgJET1JYpL6kZfaGTxkTfuemJq4Ko

--

--