Storj Share daemon doesn’t register itself as a service on Ubuntu systems. You’ll have to manually start it each time you restart your Ubuntu machine. Be it a desktop, a server or a raspberry pi, today we will figure out a way to auto start Storj Share node at reboot.
This is a followup to my yesterdays post how to setup Storj Share farming node on Ubuntu 16.04. But this will work for any Linux distribution. Pay special attention to your username and storjshare config file path.
Why Start Storj Share node at reboot?
It’s not a big deal if you only have one node. You only have to run two commands to get your node up and running again. But this can be a headache if you’re managing multiple Storj nodes on multiple machines. I currently have five nodes setup on five machines. I really don’t want to login to each server and manually start nodes each time I have a power outage.
Create a startup script to start Storjshare daemon and node
This is the method from Storj Share on Raspberry Pi documentation. It’s the official way to start Storj Share node at reboot. It works on any Linux distribution.
Login you your machine as tjosm. It’s the user we created when installing Storjshare daemon. And start by creating an env file,
env > ~/.env
Create an empry file for the script,
Paste following lines,
#!/bin/bash . $HOME/.bashrc . $HOME/.profile . $HOME/.env APP=$(ps aux | grep -v grep | grep storjshare) if [ -z "$APP" ]; then echo "Restart storjshare-daemon" storjshare daemon fi APP=$(ps aux | grep -v grep | grep 'farmer.js --config') if [ -z "$APP" ]; then echo "Restart farmers" storjshare start --config $HOME/.config/storjshare/configs/node.json fi
Save and exit. Note the path to storjshare config file towards the end. Change it accordingly if you have a different name than node.json. Save and exit. Now make it executable,
chmod +x ~/watchdog.sh
We’ll now create a cronjob to run watchdog.sh after reboot. So open crontab.
You’ll be asked to select an editor if this is your first attempt at editing crontab. Nano is the best editor for the job. So hit 2 and enter to select nano text editor. Now scroll down to the end of the file and paste following line.
Save and exit. Finally, test the script by rebooting your machine.