-
Notifications
You must be signed in to change notification settings - Fork 0
LDLN Stack Installation
These are instructions for installing the LDLN software stack to a single machine.
If you are setting up LDLN for development purposes, we suggest using Vagrant: https://github.com/LDLN/vagrant-dev
Alternatively, if you started setup with the manual Raspberry Pi 2 Node Setup and don't have an ethernet internet connection on the Base Station, you'll want to refer to how to connect the Base Station to a local wifi network, so you can install the following items from the Internet.
Here's a nice resource for which version of golang to install based on your pi: http://dave.cheney.net/unofficial-arm-tarballs
Why?
Compiling and linking Go programs can consume over 100mb of ram so it is recommended that the memory split be adjusted in favor of the main processor, at least while working with Go code. The Raspbian distribution makes this very easy with the raspi-config utility.
Source: http://dave.cheney.net/2012/09/25/installing-go-on-the-raspberry-pi
sudo raspi-config
Go to: Advanced Options > Memory Split
Allocate 16MB to GPU/Video Core and the rest to the CPU
Reboot system in the dialog or manually reboot:
sudo shutdown -r now
These are instructions for installing go1.4.2 on a raspberry pi.
Note: depending on your pi's internet connection, it may be faster to download to your laptop and sftp onto the pi for the next step.
You should probably go here: https://golang.org/dl/ and download the most recent version under ARMv6
cd
wget http://dave.cheney.net/paste/go1.4.2.linux-arm~multiarch-armv6-1.tar.gz
sudo tar -C /usr/local -xzf go1.4.2.linux-arm~multiarch-armv6-1.tar.gz
As pi user:
mkdir $HOME/go
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
Add paths to .profile:
nano ~/.profile
Add:
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
Sources:
http://dave.cheney.net/2012/09/25/installing-go-on-the-raspberry-pi http://dave.cheney.net/unofficial-arm-tarballs http://golang.org/doc/install http://golang.org/doc/code.html
Visit https://golang.org/dl/ and find the link and checksum for the version you'd like to install, then install to your server as follows:
curl -O https://storage.googleapis.com/golang/go1.7.5.linux-amd64.tar.gz
sha256sum go1.7.5.linux-amd64.tar.gz
tar xvf go1.7.5.linux-amd64.tar.gz
sudo chown -R root:root ./go
sudo mv go /usr/local
Set paths:
sudo nano ~/.profile
Add lines:
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
Save file and source it:
source ~/.profile
Create the "GOPATH" directory:
mkdir $HOME/go
Sources: https://www.digitalocean.com/community/tutorials/how-to-install-go-1-6-on-ubuntu-16-04
sudo apt-get install gcc libc6-dev git mercurial bzr -y --force-yes --fix-missing
Required Libraries:
go get github.com/revel/revel
go get github.com/revel/cmd/revel
go get golang.org/x/crypto/bcrypt
go get github.com/nu7hatch/gouuid
go get labix.org/v2/mgo
go get golang.org/x/net/websocket
go get github.com/gorilla/websocket
go get github.com/hashicorp/mdns
go get github.com/revel/modules/static
LDLN Packages:
go get github.com/ldln/core
go get github.com/ldln/web-app
go get github.com/ldln/websocket-server
go get github.com/ldln/websocket-client
go get github.com/ldln/serial-server
If you get a message saying "no buildable Go source files" when getting ldln/core or ldln/web-app, you can ignore that message. ldln/core does not need to be built, and ldln/web-app has a special build process.
cd /home/pi/go/src
revel build github.com/ldln/web-app /home/pi/go/bin/web-app
This is only for the manual running of applications and testing that your install works. You will create a startup script later on anyways.
MongoDB will need to be installed on the local machine before these can run.
# run web app
sudo $GOPATH/bin/web-app/run.sh
# run other programs
sudo $GOPATH/bin/websocket-server
sudo $GOPATH/bin/websocket-client
sudo $GOPATH/bin/serial-server
- web-app should be listening on port 80 for production, or 9000 for development.
- websocket-server should be listening on port 8080
If you are running Raspian Jessie, you can “apt-get install mongodb”. This will result in an install of MongoDB v2.4. Good enough for most uses and you get a working mongo shell 😉
MongoDb will need to be installed on the same host as the LDLN stack. There are many ways to do it. See: http://docs.mongodb.org/manual/installation/. Journaling must be enabled for MongoDB to recover after a hard shutdown (which is usually the case for Raspberry Pis).
NOTE: If there's issues running the mongo server (check it with sudo service mongodb status), delete the mongodb.lock file and try restarting the server. If that fixes it, it may be that journaling has screwed up.
Note: for these two steps at the portion where you edit the mongodb.service file use the following to enable journaling instead of what's in the tutorial:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf --journal
[Install]
WantedBy=multi-user.target
http://andyfelong.com/2016/01/mongodb-3-0-9-binaries-for-raspberry-pi-2-jessie/
http://andyfelong.com/2015/02/mongodb-on-the-raspberry-pi-2/ (executables link at the bottom)
- Download binary:
wget http://www.widriksson.com/wp-content/uploads/2014/02/mongodb-rpi_20140207.zip
unzip mongodb-rpi_20140207.zip
- Create mongo user, create directories, and configure startup:
sudo su
adduser --firstuid 100 --ingroup nogroup --shell /etc/false --disabled-password --gecos "" --no-create-home mongodb
cp -R mongodb-rpi/mongo /opt
chmod +x /opt/mongo/bin/*
mkdir /var/log/mongodb
chown mongodb:nogroup /var/log/mongodb
mkdir /var/lib/mongodb
chown mongodb:nogroup /var/lib/mongodb
cp mongodb-rpi/debian/init.d /etc/init.d/mongod
cp mongodb-rpi/debian/mongodb.conf /etc/
ln -s /opt/mongo/bin/mongod /usr/bin/mongod
chmod u+x /etc/init.d/mongod
- Add startup scripts
update-rc.d mongod defaults
- Enable journaling in the startup script:
sudo nano /etc/init.d/mongod
- Find
DAEMON_OPTSand add--journal:
DAEMON_OPTS="$DAEMON_OPTS --journal"
- Start Scripts
/etc/init.d/mongod start
- Create landline database
/opt/mongo/bin/mongo
> use landline
> exit
- View MongoDB stats page: http://192.168.0.1:28017/
Source: http://www.widriksson.com/install-mongodb-raspberrypi/
You can either install Tilestream or Tilestache. Tilestream has problems building on a Raspberry Pi.
# get pip (if you don't already have it)
sudo apt-get install python-pip
# install jpeg library need by Pillow and python-dev
sudo apt-get install libjpeg-dev
sudo apt-get install python2.7-dev
# install tilestashe
sudo pip install TileStache
#note: TileStache does not work on python 3.2. you may need to make and install the python 3.4 . If so...
Follow these instructions:
http://depado.markdownblog.com/2015-03-12-short-tutorial-raspbian-python3-4-rpi-gpio
Create a config file sudo nano /home/pi/tilestache.cfg
{
"cache":
{
"name": "Disk",
"path": "/tmp/stache",
"umask": "0000"
},
"layers":
{
"LDLNNYC":
{
"provider": {
"name": "mbtiles",
"tileset": "/home/pi/mbtiles/LDLNNYC.mbtiles"
}
}
}
}
In the example, maptiles file is: /home/pi/mbtiles/LDLNNYC.mbtiles
To start up, you enter something like this below. You will create this entry in the startup script later in this section.
/usr/local/bin/tilestache-server.py --config /home/pi/tilestache.cfg --ip 0.0.0.0 --port 8888
Source: http://tilestache.org/
wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb
rm node_latest_armhf.deb
node -v
Source: http://www.andrewconnell.com/blog/setup-node-js-on-raspberry-pi-2-b
npm by default uses an https registry, which doesn't work on the Pi 2 (presumably because of something to do with its trusted certificate authorities list). This can be easily resolved by simply switching to the http version:
npm config set registry http://registry.npmjs.org/
Or you can simply set ssl strict validation to false for npm:
npm config set strict-ssl false
Each of these adds a line to ~/.npmrc which is read each time npm starts.
You can get the latest version of node this way:
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get update
sudo apt-get install nodejs npm
Sources: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-an-ubuntu-14-04-server https://github.com/mapbox/node-sqlite3/issues/256
npm install sqlite3
This might take a long time.
Source: https://github.com/mapbox/tilestream
git clone https://github.com/mapbox/tilestream.git
cd tilestream
npm install
Start it:
./index.js start
You can set the host to listen on like this:
./index.js start --host 192.168.0.1
You will have to create MBTiles. You can learn how to do it here: https://www.mapbox.com/blog/create-a-custom-map-of-your-city-in-30-minutes-with-tilemill-and-openstreetmap/
Then upload .mbtiles here:
mkdir /home/pi/mbtiles
sudo apt-get update sudo apt-get install libnss-mdns
Then configure /etc/avahi/services/ldln.service:
- sudo nano /etc/avahi/services/ldln.service
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">LDLN Basestation on %h</name>
<service>
<type>_ldln._tcp</type>
<port>8080</port>
</service>
</service-group>
Restart avahi daemon:
sudo /etc/init.d/avahi-daemon restart
You can scan for this service from your Mac dns-sd -B _services._dns-sd._udp
sudo nano /etc/init.d/ldln.sh
Put in:
#!/bin/bash
## BEGIN INIT INFO
# Provides: some_name
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start access point daemons at boot time
# Description: Enable service provided by daemon.
## END INIT INFO
# start the avahi/bonjour server
service avahi-daemon start
# start LDLN components
/home/pi/go/bin/web-app/run.sh &
/home/pi/go/bin/websocket-server &
/home/pi/go/bin/websocket-client &
# start tilestream (if you did this)
/home/pi/node-v0.10.2-linux-arm-pi/bin/node /home/pi/tilestream/index.js start --host 192.168.0.1 --tiles=/home/pi/tilestream/tiles
# start tilestache (if you did this)
/usr/local/bin/tilestache-server.py --config /home/pi/tilestache.cfg --ip 0.0.0.0 --port 8888
-
Make executable and add to startup:
sudo chmod +x /etc/init.d/ldln.sh sudo update-rc.d ldln.sh defaults -
Test to ensure it works:
sudo /etc/init.d/ldln.sh
Get latest:
go get -u all
Then rebuild:
cd /home/pi/go/src
revel build github.com/ldln/web-app /home/pi/go/bin/web-app
go install github.com/ldln/websocket-server
go install github.com/ldln/websocket-client
go install github.com/ldln/serial-server
...
Then restart:
sudo reboot