Best way to deploy/run on Raspberry Pi?


#1

For a single app, single use appliance type Raspberry Pi setup (MPD music server, serving meteor app as client/controller) what would be the best method to run/deploy meteor on the pi?

Should I just rig it to call “meteor run” on startup? Or manually bundle and deploy? Or muck about with the latest MUP from Kadira?

With the first methods I’d have to install the meteor version for ARM, not sure how stable that is? With MUP I’m not sure I’d have to deal with that since it deploys a docker container… so I’d just have to setup docker on Pi… again not sure how stable that is.

Any input would be greatly appreciated.


#2

The universal meteor fork is great and I haven’t had any problems with stability and installation is a breeze. I don’t think you could use MUP since it’s still going to be missing all of the binary dependancies to run meteor on the ARM processor of the Pi.

As far as launching a meteor app on startup, this is what worked for me:

  1. Created a systemd unit file at /etc/systemd/system/meteor.service with the following contents:
[Unit]
Description=Crucible
	
[Service]
ExecStart=/usr/bin/meteor 
WorkingDirectory=/home/pi/<meteor app repo>
User=pi
	
[Install]
WantedBy=multi-user.target

then run the following commands to startup the new service

sudo systemctl daemon-reload   # reloads all the services from disk
sudo service crucible start # or stop | restart | status ...

This starts up meteor, but on port 3000. The only way I figured out how to forward port 80 to meteor automatically on boot was to change the rc.local file to:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 3000
iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

exit 0

I did this a few months ago and my notes are a little rusty. I might have had to change the TimeoutSec to 15 seconds in the /lib/systemd/system/rc-local.service file, but I’m not sure.

Also, I’m pretty sure this can be condensed and made simpler, but I had to move on once I got it working.

Let me know if you have any questions!


#3

Thanks, I will give that a shot.

I have only experimented with docker a little bit. But as I understand it, each docker container sort of has its own OS, so my thinking with that was that the container would be standard *nix and run standard meteor, and the ARM/pi docker install would handle the rest. But I could be pretty wrong about that, or it could just be more complicated than necessary.

Will probably try moving my project over to the pi tomorrow and see if I can get it running.


#4

The universal install went okay, though I had to go the somewhat manual route. I was a little concerned as it lists support for PiB, Pi2, but there’s no mention of Pi3, but I think it should be fine.

So far I haven’t been able to get MongoDB to start successfully in meteor, but it’s probably some file permission or configuration issue I’ll be able to sort when I get back to it with fresh eyes.

My project was created using Meteor 1.4 on Ubuntu, so moving it to the 1.3 Universal will probably take a bit of tweaking, but nothing major.

Thanks for the rc.local/iptables trick. For my use case, that seems better than installing and configuring nginx just to forward ports to one app.


#5

The universal build definitely runs on a Pi3 - that’s our setup. If you’re having trouble with mongo, I’d start looking for traces of the vanilla meteor installation. Mongo is one of those binary dependancies that had to be recompiled to run on the Pi.

Also, there was a the typo in one of the commands I suggested in the last post - it should be sudo service meteor start instead of sudo service crucible start. Crucible was what I called my unit file… Hope that didn’t trip you up.

Finally, I just realized that I added a symlink for meteor in /usr/bin that points to /home/pi/meteor/meteor.


#6

Thanks for the tips.
Haven’t had any luck with mongo yet. But you’re probably right about it having to do with traces of vanilla.
I installed the universal build. But then, without thinking, cloned my project. Tried to run it, which didn’t work at all.
So I meteor created a new project folder on the pi, then copied just my code over to the new project folder, hoping that would be that.

Apparently either trying to run a project with vanilla first, or something that I copied over has mucked things up. I’ll spend a bit more time trying to track it down, then I’ll probably clear things out, reinstall and be very careful about bringing my code over.


#7

Even with a freshly created project file, I get Unexpected mongo exit code 100. Restarting.
Going to walk back through the install process, see if I did something wrong somewhere.


#8

Alright, started over with reinstalling the universal build and things went more smoothly.
Got the mongo error 1 rather than 100, which was an easy locale fix.
Tested with todos, got that working. Added packages and carefully copied over only my code files.
App started successfully!!

Thanks for all the tips. Hopefully I’ll get through the rest of the setup for auto starting and port forwarding, etc more smoothly.


#9

So far, so good.
For whatever reason my service isn’t starting automatically on reboot, so I’ll have to go over that again, but just having it set up as a service is pretty convenient.

The port forwarding works nicely. I have set up the Pi3 to use it’s built in wifi as a WAP, so I can easily connect to it and access the meteor app. Still needs some tweaking, but I’m pretty happy with it so far.

Again, thanks for all the help.


#10

Glad to hear it worked out. Did you figure out starting meteor on boot? I have working reliably in my setup. What was the error?

Sorry I disappeared for awhile, we missed a release and it’s been a fire drill for the past 3 weeks… But now I’m finally finding some time to work on my pi/meteor project again!