Skip to content

Install Nodel as an init.d (Raspberry Pi) process

scroix edited this page May 29, 2022 · 6 revisions

The latest Nodel JAR contains entry-points to allow use with JSVC.

There are two options to install Nodel. The first is to use this installer script, which also installs a basic node on the machine:

https://gist.github.com/scroix/e820d66410e078f59d7757ddc6200835

This is a modification of a script developed by Richard Hulse of the Museum of New Zealand Te Papa Tongarewa for Ubuntu 16.04.

If you're on a network with a proxy, you'll want to do two things before you run the script.

  • (1) Add http_proxy=http://host:_port and https_proxy=https://host:port to your ~/.bashrc profile
  • (2) Defaults env_keep = "http_proxy https_proxy" added to /etc/sudoers with visudo

Otherwise you can do it manually:

Copy Nodel files into place. Replace with your nodel version.

sudo mkdir /opt/nodel
sudo cp nodelHost-<nodelversion>.jar /opt/nodel/nodel.jar

Install JSVC

sudo apt-get install jsvc

Test for installation of Java (comes with new Raspbian builds)

java -version

If you do not see the Java version number, install Java.

sudo apt-get update && sudo apt-get install oracle-java8-jre

Repeat the test above to verify installation.

Run on the console (for testing):

cd /opt/nodel
sudo java -cp nodel.jar org.nodel.jyhost.Launch

After running this test, you should be able to view Nodel in a browser.

Run on the console using jsvc (for testing):

sudo /usr/bin/jsvc -home /usr/lib/jvm/java-8-openjdk-armhf -pidfile /var/run/jsvc.pid -cp /opt/nodel/nodel.jar:/usr/share/java/commons-daemon.jar org.nodel.nodelhost.Service

After running this test, you should be able to view Nodel in a browser.

If the computer is multi-homed (has two or more active network interfaces) then you will need to create a bootstrap.json file before proceeding. Check _example_bootstrap.json for details.

Create daemon startup script:

sudo nano /etc/init.d/nodel 

Copy and paste the following code into the editor

#!/bin/sh
### BEGIN INIT INFO
# Provides:          nodel
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: nodel
# Description:       nodel daemon
### END INIT INFO

#change to working directory
cd /opt/nodel

# Setup variables
EXEC="/usr/bin/jsvc"
JAVA_HOME="/usr/lib/jvm/jdk-7-oracle-armhf"
CLASS_PATH="/opt/nodel/nodel.jar:/usr/share/java/commons-daemon.jar"
CLASS=org.nodel.nodelhost.Service
USER=root
PID="/var/run/nodel.pid"

do_exec() {
    $EXEC -home $JAVA_HOME -cp $CLASS_PATH -pidfile $PID $CLASS
}

do_stop() {
    $EXEC -stop -home $JAVA_HOME -cp $CLASS_PATH -pidfile $PID $CLASS
}

case "$1" in
    start)
        echo "Starting Nodel"
        do_exec
            ;;
    stop)
        echo "Stopping Nodel"
        do_stop
            ;;
    restart)
        if [ -f "$PID" ]; then
            echo "Restarting Nodel"
            do_stop
            do_exec
        else
            echo "service not running, will do nothing"
            exit 1
        fi
            ;;
    *)
            echo "usage: daemon {start|stop|restart}" >&2
            exit 3
            ;;
esac

Press ctrl-x to exit and save the file

Set execute permissions:

sudo chmod a+x /etc/init.d/nodel

Add to startup

sudo update-rc.d nodel defaults

Reboot the Pi and Nodel should start automatically

sudo shutdown -r now