Last active
August 29, 2015 14:14
-
-
Save bripkens/2856221fc61ba770eac1 to your computer and use it in GitHub Desktop.
Home automation raspberry PI setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!upstart | |
# put in /etc/init/homeAutomationBackend.conf | |
description "Home Automation Backend Server" | |
author "Ben Ripkens" | |
start on startup | |
stop on shutdown | |
respawn | |
script | |
export HOME="/root" | |
echo $$ > /var/run/home-automation-backend.pid | |
exec /usr/local/bin/node /opt/home-automation/backend >> /var/log/home-automation-backend.sys.log 2>&1 | |
end script | |
pre-start script | |
echo "Pulling latest version from repository" >> /var/log/home-automation-backend.sys.log | |
git --git-dir /opt/home-automation/backend/.git --work-tree /opt/home-automation/backend pull origin master >> /var/log/home-automation-backend.sys.log 2>&1 | |
# Date format same as (new Date()).toISOString() for consistency | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/home-automation-backend.sys.log | |
end script | |
pre-stop script | |
rm /var/run/yourprogram.pid | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/home-automation-backend.sys.log | |
end script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# partially based on | |
# https://blog.codecentric.de/en/2013/03/home-automation-with-angularjs-and-node-js-on-a-raspberry-pi/ | |
# configure raspberry pi: | |
sudo raspi-config | |
# passwordless SSH: | |
cat ~/.ssh/id_rsa.pub | ssh pi@raspberrypi "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys" | |
# upgrade | |
sudo apt-get update | |
sudo apt-get -y upgrade | |
# reboot | |
sudo reboot | |
# install stuff | |
sudo apt-get install -y build-essential openssl libssl-dev pkg-config curl nginx tmux vim git-core upstart | |
# change keyboard | |
sudo vi /etc/default/keyboard | |
# change gb => de | |
# enter tmux session to be able to detach | |
tmux | |
# install node.js | |
# see http://shapeshed.com/compiling-nodejs-from-source-on-ubuntu-10-04/ | |
cd /usr/local/src | |
sudo mkdir node | |
cd node | |
sudo wget http://nodejs.org/dist/v0.10.36/node-v0.10.36.tar.gz | |
sudo tar -xzf node-v0.10.36.tar.gz | |
cd node-v0.10.36 | |
sudo ./configure | |
sudo make | |
sudo make install | |
# to make a backup | |
sudo dd bs=1m if=/dev/disk2 of=~/image-`date +%y-%m-%d`.img | |
# or compressed | |
# make backup | |
sudo dd bs=4M if=/dev/sdb | gzip > /home/your_username/image`date +%d%m%y`.gz | |
# apply backup | |
sudo gzip -dc /home/your_username/image.gz | dd bs=4M of=/dev/sdb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment