Skip to content

Skywire Systemd Service

asxtree edited this page Jan 7, 2019 · 12 revisions

skywire logo

Skywire systemd service setup guide

This guide assumes that you have read and understood the readme.md and installed Skywire using one of the several guides on this wiki. This guide also asumes that you've installed skywire on an armbian image and have the $GOPATH set to /root/go or it is installed on a raspberry image and have the $GOPATH set to /home/pi/go

Table of Contents


Introduction

This guide outlines the necessary steps to add the Skywire software to the systemd services so that it automatically starts at boot. This way you don't have to manually start the manager & node processes each time you reboot your boards.

Requirements

  • Installed Skywire Software on the board and image of your choice.
  • Stop the current skywire node and manager processes (if they are already running).
  • Disable the currently autostart scripts that you are using (if you are using).

To install skywire check our Github page or use one fo the DIY Skywire guides.

If you are already running skywire manager and node processes you'll need to stop them as follow. Follow these steps to to stop the manager process and to stop the node process here.

If you are using an autostart scripts from these three guides, follow the steps described to disable them.

To stop and disable asxtree's systemd manager service do as follows only on the manager board:

systemctl stop skymanager.service

systemctl disable skymanager.service

To stop and disable asxtree's systemd node service do as follows only on all boards:

systemctl stop skynode.service

systemctl disable skynode.service

To stop and disable adhaelon's systemd manager service do as follows only on the manager board:

sudo systemctl stop manager.service

sudo systemctl disable manager.service

To stop and disable adhaelon's systemd node service do as follows only on all boards (on the manager board might not be needed):

sudo systemctl stop secondary.service

sudo systemctl disable secondary.service
sudo -i

cd /etc

crontab -e

Now scroll to the end and comment the following line @reboot /etc/init.d/MyScript.sh to look like #@reboot /etc/init.d/MyScript.sh, notice the # sign.

Press CTRL+x then type y and press ENTER key to save and exit.

Then move MyScript.sh from /etc/init.d/ to $HOME with the following command mv -f /etc/init.d/MyScript.sh $HOME.

Usage

Setting up the Systemd service for executing Skywire at boot.

Use official systemd service on Armbian image

Edit .bashrc and comment the initial env variables on all boards

If you already installed skywire on your board and set the environment variables in .bashrc file youll need to comment them because the official systemd services use a special file for them, so start by typing:

nano /root/.bashrc

Find the following lines and comment them by writting # in the begining of each line, like:

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

Press CTRL+x then type y and press ENTER key to save and exit.

Pull the latest updates from github on all boards

In order to have the systemd service files we need to pull the latest update from github, so type:

cd /root/go/src/github.com/skycoin/skywire/

git reset --hard

git pull origin master

Verify that you have the systemd service files by typing:

ls -al static/script/upgrade/

And you should see the folowing followings:

drwxr-xr-x 2 root root  4096 Dec 20 09:38 data
-rwxr-xr-x 1 root root 35429 Dec 20 09:38 one_time_upgrade
-rw-r--r-- 1 root root  4308 Dec 20 09:38 README.md

If you DON'T SEE those files do the followings. Delete the skywire folder and clone it again by typing:

cd ..

rm -rf skywire/

git clone https://github.com/skycoin/skywire.git

cd skywire/cmd/

go install -v ./...

If you DO SEE those files continue with the update:

cd cmd/

go install -v ./...

Start adjusting the systemd service files for your environment

Create a symbolic link skywire.defaults env file to /etc/skywire on all boards

cd /etc/default

ln -s /root/go/src/github.com/skycoin/skywire/static/script/skywire.defaults skywire

Modify skywire.defaults env file on all boards

nano /etc/default/skywire

Now change this part of the file as follows:

# Default variables for the entire skywire work, this needs to be in
# the environment to make it work properly

# IP of the manager, by default 192.168.0.2
# if you use a custom IP set just change the manager IP
# here to apply it system wide.
- MANAGER_IP=192.168.0.2                                             - Change the IP with your manager IP

# Go related variables
GOROOT=/usr/local/go
- GOPATH=/usr/local/skywire/go                                       - Replace with your actual GOPATH like ${HOME}/go
- PATH="/usr/local/go/bin:/usr/local/skywire/go/bin:${PATH}"         - Replace with ${GOROOT}/bin:${GOPATH}/bin:${PATH}

# Runtime variables
- HOME=/root                                                         - Move in "Go related variables"
TMP_DIR=/tmp/skywire-info

In the end it should look like this but pay attention to your MANAGER_IP, this is just an example and you should put your manager's node IP:

# Default variables for the entire skywire work, this needs to be in
# the environment to make it work properly

# IP of the manager, by default 192.168.0.2
# if you use a custom IP set just change the manager IP
# here to apply it system wide.
MANAGER_IP=192.168.2.2

# Go related variables
HOME=/root
GOROOT=/usr/local/go
GOPATH=${HOME}/go
PATH=${GOROOT}/bin:${GOPATH}/bin:${PATH}

# Runtime variables
TMP_DIR=/tmp/skywire-info

Press CTRL+x then type y and press ENTER key to save and exit.

Reload skywire.defaults on all boards

source /etc/default/skywire

Copy the official Systemd service files

Copy the manager service file only on the manager board

cp -r /root/go/src/github.com/skycoin/skywire/static/script/upgrade/data/skywire-manager.service /etc/systemd/system/

Copy the node service file only on the node designated boards (not manager)

cp -r /root/go/src/github.com/skycoin/skywire/static/script/upgrade/data/skywire-node.service /etc/systemd/system/

Modify the official systemd manager service file only on the manager board

nano /etc/systemd/system/skywire-manager.service

Now change this part of the file as follows:

...
[Service]
Type=oneshot
- ExecStart=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/manager_start   - Replace `/usr/local/skywire` with the folder where is `go` located like `/root`
- ExecStop=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/stop          - Replace `/usr/local/skywire` with the folder where is `go` located like `/root`
RemainAfterExit=yes
...

In the end it should look like this but pay attention to your path where go is located:

...
[Service]
Type=oneshot
ExecStart=/root/go/src/github.com/skycoin/skywire/static/script/manager_start
ExecStop=/root/go/src/github.com/skycoin/skywire/static/script/stop
RemainAfterExit=yes
...

Press CTRL+x then type y and press ENTER key to save and exit.

Modify the official systemd node service file only on the node designated boards (not manager)

nano /etc/systemd/system/skywire-node.service

Now change this part of the file as follows:

...
[Service]
Type=oneshot
- ExecStart=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/node_start   - Replace `/usr/local/skywire` with the folder where is `go` located like `/root`
- ExecStop=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/stop          - Replace `/usr/local/skywire` with the folder where is `go` located like `/root`
RemainAfterExit=yes
...

In the end it should look like this but pay attention to your path where go is located:

...
[Service]
Type=oneshot
ExecStart=/root/go/src/github.com/skycoin/skywire/static/script/node_start
ExecStop=/root/go/src/github.com/skycoin/skywire/static/script/stop
RemainAfterExit=yes
...

Press CTRL+x then type y and press ENTER key to save and exit.

Enable the official Systemd service files

Reload the deamon and enable the systemd manager service only on the manager board by typing:

systemctl daemon-reload

systemctl enable skywire-manager.service

Reload the deamon and enable the systemd node service only on the node designated boards (not manager) by typing:

systemctl daemon-reload

systemctl enable skywire-node.service

Modify the official manager_start service file only on the manager board

nano /root/go/src/github.com/skycoin/skywire/static/script/manager_start

Now change this part of the file as follows:

...
# local vars
- SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script   - Replace `/usr/local/skywire` with the folder where is `go` located like `/root`
...

In the end it should look like this but pay attention to your path where go is located:

...
# local vars
SKYWIRE_UNIX_SCRIPTS=/root/go/src/github.com/skycoin/skywire/static/script
...

Press CTRL+x then type y and press ENTER key to save and exit.

Modify the official node_start service files only on the node designated boards (not manager)

nano /root/go/src/github.com/skycoin/skywire/static/script/node_start

Now change this part of the file as follows:

...
# local vars
- SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script   - Replace `/usr/local/skywire` with the folder where is `go` located like `/root`
...

In the end it should look like this but pay attention to your path where go is located:

...
# local vars
SKYWIRE_UNIX_SCRIPTS=/root/go/src/github.com/skycoin/skywire/static/script
...

Press CTRL+x then type y and press ENTER key to save and exit.

Modify the official start, stop and update service files on all boards

The start service file:

nano /root/go/src/github.com/skycoin/skywire/static/script/start

Now change this part of the file as follows:

...
# local vars
- SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script   - Replace `/usr/local/skywire` with the folder where is `go` located like `/root`
...

In the end it should look like this but pay attention to your path where go is located:

...
# local vars
SKYWIRE_UNIX_SCRIPTS=/root/go/src/github.com/skycoin/skywire/static/script
...

Press CTRL+x then type y and press ENTER key to save and exit.

The stop service file

nano /root/go/src/github.com/skycoin/skywire/static/script/stop

Now change this part of the file as follows:

...
# local vars
- SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script   - Replace `/usr/local/skywire` with the folder where is `go` located like `/root`
...

In the end it should look like this but pay attention to your path where go is located:

...
# local vars
SKYWIRE_UNIX_SCRIPTS=/root/go/src/github.com/skycoin/skywire/static/script
...

Press CTRL+x then type y and press ENTER key to save and exit.

The update service file

nano /root/go/src/github.com/skycoin/skywire/static/script/update

Now change this part of the file as follows:

...
# local vars
- SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script   - Replace `/usr/local/skywire` with the folder where is `go` located like `/root`
...

In the end it should look like this but pay attention to your path where go is located:

...
# local vars
SKYWIRE_UNIX_SCRIPTS=/root/go/src/github.com/skycoin/skywire/static/script
...

Press CTRL+x then type y and press ENTER key to save and exit.

Start manager and node services

To start the manager service on the manager board (this will also start the node service so no need to start also skywire-node.service) type:

systemctl start skywire-manager.service

To start the node service on the rest of the node boards excluding the manager board type:

systemctl start skywire-node.service

Use official systemd service on Raspberry Pi Raspbian

Edit .bashrc or .profile and comment the initial env variables on all boards

Depending on what guide you followed to install skywire on your Raspberry Pi you've set the env variables either in .bashrc, or in .profile

If you already installed skywire on your board and set the environment variables in .bashrc or .profile file youll need to comment them because the official systemd services use a special file for them, so start by typing:

sudo nano ~/.bashrc

or

sudo nano ~/.profile

Find the following lines and comment them by writting # in the begining of each line, like:

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

Press CTRL+x then type y and press ENTER key to save and exit.

Pull the latest updates from github on all boards

In order to have the systemd service files we need to pull the latest update from github, so type:

cd /home/pi/go/src/github.com/skycoin/skywire/

git reset --hard

git pull origin master

Verify that you have the systemd service files by typing:

ls -al static/script/upgrade/

And you should see the folowing followings:

drwxr-xr-x 2 root root  4096 Dec 20 09:38 data
-rwxr-xr-x 1 root root 35429 Dec 20 09:38 one_time_upgrade
-rw-r--r-- 1 root root  4308 Dec 20 09:38 README.md

If you DON'T SEE those files do the followings. Delete the skywire folder and clone it again by typing:

cd ..

sudo rm -rf skywire/

git clone https://github.com/skycoin/skywire.git

cd skywire/cmd/

go install -v ./...

If you DO SEE those files continue with the update:

cd cmd/

go install -v ./...

Start adjusting the systemd service files for your environment

Create a symbolic link skywire.defaults env file to /etc/skywire on all boards

cd /etc/default/

sudo ln -s /home/pi/go/src/github.com/skycoin/skywire/static/script/skywire.defaults skywire

Modify skywire.defaults env file on all boards

sudo nano /etc/default/skywire

Now change this part of the file as follows:

# Default variables for the entire skywire work, this needs to be in
# the environment to make it work properly

# IP of the manager, by default 192.168.0.2
# if you use a custom IP set just change the manager IP
# here to apply it system wide.
- MANAGER_IP=192.168.0.2                                             - Change the IP with your manager IP

# Go related variables
GOROOT=/usr/local/go
- GOPATH=/usr/local/skywire/go                                       - Replace with your actual GOPATH like ${HOME}/go
- PATH="/usr/local/go/bin:/usr/local/skywire/go/bin:${PATH}"         - Replace with ${GOROOT}/bin:${GOPATH}/bin:${PATH}

# Runtime variables
- HOME=/root                                                         - Move in "Go related variables"
TMP_DIR=/tmp/skywire-info

In the end it should look like this but pay attention to your MANAGER_IP, this is just an example and you should put your manager's node IP:

# Default variables for the entire skywire work, this needs to be in
# the environment to make it work properly

# IP of the manager, by default 192.168.0.2
# if you use a custom IP set just change the manager IP
# here to apply it system wide.
MANAGER_IP=192.168.2.2

# Go related variables
HOME=/home/pi
GOROOT=/usr/local/go
GOPATH=${HOME}/go
PATH=${GOROOT}/bin:${GOPATH}/bin:${PATH}

# Runtime variables
TMP_DIR=/tmp/skywire-info

Press CTRL+x then type y and press ENTER key to save and exit.

Reload skywire.defaults on all boards

source /etc/default/skywire

Copy the official Systemd service files

Copy the manager service file only on the manager board

sudo cp -r /home/pi/go/src/github.com/skycoin/skywire/static/script/upgrade/data/skywire-manager.service /etc/systemd/system/

Copy the node service file only on the node designated boards (not manager)

sudo cp -r /home/pi/go/src/github.com/skycoin/skywire/static/script/upgrade/data/skywire-node.service /etc/systemd/system/

Modify the official systemd manager service file only on the manager board

sudo nano /etc/systemd/system/skywire-manager.service

Now change this part of the file as follows:

...
[Service]
Type=oneshot
- ExecStart=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/manager_start   - Replace `/usr/local/skywire` with the folder where is `go` located like `/home/pi`
- ExecStop=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/stop          - Replace `/usr/local/skywire` with the folder where is `go` located like `/home/pi`
RemainAfterExit=yes
...

In the end it should look like this but pay attention to your path where go is located:

...
[Service]
Type=oneshot
ExecStart=/home/pi/go/src/github.com/skycoin/skywire/static/script/manager_start
ExecStop=/home/pi/go/src/github.com/skycoin/skywire/static/script/stop
RemainAfterExit=yes
...

Press CTRL+x then type y and press ENTER key to save and exit.

Modify the official systemd node service file only on the node designated boards (not manager)

sudo nano /etc/systemd/system/skywire-node.service

Now change this part of the file as follows:

...
[Service]
Type=oneshot
- ExecStart=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/node_start   - Replace `/usr/local/skywire` with the folder where is `go` located like `/home/pi`
- ExecStop=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/stop          - Replace `/usr/local/skywire` with the folder where is `go` located like `/home/pi`
RemainAfterExit=yes
...

In the end it should look like this but pay attention to your path where go is located:

...
[Service]
Type=oneshot
ExecStart=/home/pi/go/src/github.com/skycoin/skywire/static/script/node_start
ExecStop=/home/pi/go/src/github.com/skycoin/skywire/static/script/stop
RemainAfterExit=yes
...

Press CTRL+x then type y and press ENTER key to save and exit.

Enable the official Systemd service files

Reload the deamon and enable the systemd manager service only on the manager board by typing:

sudo systemctl daemon-reload

sudo systemctl enable skywire-manager.service

Reload the deamon and enable the systemd node service only on the node designated boards (not manager) by typing:

sudo systemctl daemon-reload

sudo systemctl enable skywire-node.service

Modify the official manager_start service file only on the manager board

sudo nano /home/pi/go/src/github.com/skycoin/skywire/static/script/manager_start

Now change this part of the file as follows:

...
# local vars
- SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script   - Replace `/usr/local/skywire` with the folder where is `go` located like `/home/pi`
...

In the end it should look like this but pay attention to your path where go is located:

...
# local vars
SKYWIRE_UNIX_SCRIPTS=/home/pi/go/src/github.com/skycoin/skywire/static/script
...

Press CTRL+x then type y and press ENTER key to save and exit.

Modify the official node_start service files only on the node designated boards (not manager)

sudo nano /home/pi/go/src/github.com/skycoin/skywire/static/script/node_start

Now change this part of the file as follows:

...
# local vars
- SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script   - Replace `/usr/local/skywire` with the folder where is `go` located like `/home/pi`
...

In the end it should look like this but pay attention to your path where go is located:

...
# local vars
SKYWIRE_UNIX_SCRIPTS=/home/pi/go/src/github.com/skycoin/skywire/static/script
...

Press CTRL+x then type y and press ENTER key to save and exit.

Modify the official start, stop and update service files on all boards

The start service file:

sudo nano /home/pi/go/src/github.com/skycoin/skywire/static/script/start

Now change this part of the file as follows:

...
# local vars
- SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script   - Replace `/usr/local/skywire` with the folder where is `go` located like `/home/pi`
...

In the end it should look like this but pay attention to your path where go is located:

...
# local vars
SKYWIRE_UNIX_SCRIPTS=/home/pi/go/src/github.com/skycoin/skywire/static/script
...

Press CTRL+x then type y and press ENTER key to save and exit.

The stop service file

sudo nano /home/pi/go/src/github.com/skycoin/skywire/static/script/stop

Now change this part of the file as follows:

...
# local vars
- SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script   - Replace `/usr/local/skywire` with the folder where is `go` located like `/home/pi`
...

In the end it should look like this but pay attention to your path where go is located:

...
# local vars
SKYWIRE_UNIX_SCRIPTS=/home/pi/go/src/github.com/skycoin/skywire/static/script
...

Press CTRL+x then type y and press ENTER key to save and exit.

The update service file

sudo nano /home/pi/go/src/github.com/skycoin/skywire/static/script/update

Now change this part of the file as follows:

...
# local vars
- SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script   - Replace `/usr/local/skywire` with the folder where is `go` located like `/home/pi`
...

In the end it should look like this but pay attention to your path where go is located:

...
# local vars
SKYWIRE_UNIX_SCRIPTS=/home/pi/go/src/github.com/skycoin/skywire/static/script
...

Press CTRL+x then type y and press ENTER key to save and exit.

Start manager and node services

To start the manager service on the manager board (this will also start the node service so no need to start also skywire-node.service) type:

sudo systemctl start skywire-manager.service

To start the node service on the rest of the node boards excluding the manager board type:

sudo systemctl start skywire-node.service
Clone this wiki locally
You can’t perform that action at this time.