-
Notifications
You must be signed in to change notification settings - Fork 17
Install Nodel as a macOS (OSX) process
Get the latest Nodel JAR. It contains entry-points to allow use with JSVC.
First, download the latest version of the Java JDK (not JRE!), or openJDK. It is good practice to compare the checksum against your download.
cd ~/Downloads
we will use the sha256 provided on the website to compare. Copy the text and use this command to compare your download
shasum -a 256 -c <<< '(hashToCompare) [mode character](filepath)'
in my case this is:
shasum -a 256 -c <<< 'f365750d4be6111be8a62feda24e265d97536712bc51783162982b8ad96a70ee *openjdk-11.0.2_osx-x64_bin.tar.gz'
and results in:
openjdk-11.0.2_osx-x64_bin.tar.gz: OK
This file is safe to use. Extract the files:
tar -xvf openjdk-11.0.2_osx-x64_bin.tar.gz
and move the resultant folder to your JVM folder:
sudo mv jdk-11.0.2.jdk/ /Library/Java/JavaVirtualMachines/
check the install has worked:
java --version
Which should result in:
openjdk 11.0.2 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
Copy Nodel files into place. Replace with your nodel version.
sudo mkdir /Library/Nodel
sudo cp nodelHost-<nodelversion>.jar /Library/Nodel/nodel.jar
Download JSVC Source and its associated sha512 hash from Apache, check the hash:
shasum -a512 -c commons-daemon-1.2.2-src.tar.gz.sha512
If it results in commons-daemon-1.2.2-src.tar.gz: OK
then extract the files:
tar -xvf commons-daemon-1.2.2-src.tar.gz
If Java 7 is in use, at the time of writing, two files require patching before jsvc is compiled.
Compile JSVC (or use pre-compiled binary) Apple Developer Tools required, with command-line tools enabled
cd commons-daemon-1.2.2-src/src/native/unix
./configure --with-java=/System/Library/Frameworks/JavaVM.framework
or, if you've used openJDK:
./configure --with-java=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/
then:
make
sudo cp jsvc /Library/Nodel
NOTE when running ./configure you are prompted to download the compiler required. An apple GUI dialog comes up and super helpfully installs it for you. Then simply rerun the ./configure command and make and the jsvc binary should be generated.
Set correct permissions
sudo chown -R root:wheel /Library/Nodel
At this point, everything should be working. But for me, the nodel jsvc service could NEVER find the JVM. It always said JVM = 0 and completely errored out. The following commands worked for me to link things together correctly (taken from http://www.thomaskioko.com/hacks/cannot-find-any-vm-in-java-home-mac/ ). Replace the javavirtualmachines version with your version as before.
cd /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents
sudo ln -s Home/jre/lib Libraries
cd Libraries
sudo ln -s server/libjvm.dylib libserver.dylib
After running the above, the below commands should work.
Run on the console(for testing): Java 6
sudo /Library/Nodel/jsvc -server -cwd /Library/Nodel -home /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home -pidfile /var/run/jsvc.pid -cp /Library/Nodel/nodel.jar org.nodel.nodelhost.Service
Java7
sudo /Library/Nodel/jsvc -server -cwd /Library/Nodel -home /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home -pidfile /var/run/jsvc.pid -cp /Library/Nodel/nodel.jar org.nodel.nodelhost.Service
Java8
sudo /Library/Nodel/jsvc -server -cwd /Library/Nodel -home /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home -pidfile /var/run/jsvc.pid -cp /Library/Nodel/nodel.jar org.nodel.nodelhost.Service
openJDK
sudo /Library/Nodel/jsvc -server -cwd /Library/Nodel/ -home /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/ -pidfile /var/run/jsvc.pid -cp /Library/Nodel/nodel.jar org.nodel.nodelhost.Service
NOTE edit java version above based on your particular release and what is installed under "javavirtualmachines" directory
After running this test, you should be able to view Nodel in a browser. (Default port is 8085)
http://<nodel_server_ip>:8085/
If not, you can start by logging the output to a text file to see where things are falling apart (note errfile, outfile, debug and verbose variables):
/Library/Nodel/jsvc -server -cwd /Library/Nodel -home /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home -pidfile /var/run/jsvc.pid -debug -verbose -outfile /Library/Nodel/outfile.txt -errfile /Library/Nodel/errfile.txt -cp /Library/Nodel/nodel.jar org.nodel.nodelhost.Service
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. This is most likely the case as all mac's come with wireless network cards, and it even seems to count lo0 as an "active network interface". Check _example_bootstrap.json for details. An example has also been provided below. The funny looking XXXXXXX type letters and numbers that is immediately following the "hardwareAddr" string. EXAMPLE:
{
"networkInterface": "ACYIC2Oq",
}
An example of my bootstrap.json file that is working:
{
"NodelHostPort": 8085,
"nodelRoot": "nodes",
"contentDirectory": "content",
"configDirectory": "config",
"cacheDirectory": "cache",
"nodelPackage": "",
"networkInterface": "ACYIC2Oq",
"disableAdvertisements": false,
"enableProgramLogging": true
}
Once you have everything working above, your test command works and you can see the webpage come up, its time to make it into a service to load on boot.
Create daemon startup script:
sh
sudo nano /Library/Nodel/daemon.sh
And populate the file with the below:
#!/bin/sh
# Setup variables
EXEC="/Library/Nodel/jsvc"
CWD="/Library/Nodel"
# Comment/uncomment java version below
# Java 6
#JAVA_HOME="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"
# Java 7
# JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home"
# JAVA 8
#JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home"
#openJDK 11
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/"
CLASS_PATH="/Library/Nodel/nodel.jar"
CLASS=org.nodel.nodelhost.Service
USER=root
PID=/var/run/jsvc.pid
do_exec() {
$EXEC -server -cwd $CWD -home $JAVA_HOME -cp $CLASS_PATH -pidfile $PID $CLASS
}
do_stop() {
$EXEC -stop -server -cwd $CWD -home $JAVA_HOME -cp $CLASS_PATH -pidfile $PID $CLASS
}
echo "Starting Nodel"
do_exec "&"
trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP
echo "Waiting for `cat $PID`"
while ps -p `cat $PID` > /dev/null; do sleep 1; done
Set execute permissions on your script:
sudo chmod a+x /Library/Nodel/daemon.sh
Create Plist file to launch the script at boot:
sudo nano /Library/LaunchDaemons/org.apache.commons.jsvc.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>org.apache.commons.jsvc</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Nodel/daemon.sh</string>
<string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/Library/Nodel</string>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
Load Plist
sudo launchctl load -w /Library/LaunchDaemons/org.apache.commons.jsvc.plist
That's it your done! test if it survives a reboot and then buy yourself a beer.
Final Thoughts:
- Make sure you have the newest version of nodel.jar installed. Older versions do not always work and there was a bug in the release till june 2016.
- OSX machines have no (WOL) Wake On LAN from S5 or OFF. So you may need to modify script.py to simply SLEEP the mac which is what i did (shutdown -s NOW). The stock shutdown command is meant for when you actually cut power to the mac (flag -u) but then you cant wake it up by WOL.
Nodel: http://nodel.io/ | White Paper