Ghost on Pi

Ghost is open source blogging platform written in Node.js that offers self hosting and hosted service.

We are going to self host Ghost on a Raspberry Pi.

This guide will take you through the steps of setting up a self hosted Ghost production environment.

I am working on this setup with a clean install of Raspbian and headless setup, you can lean how to enable SSH from here.

You can SSH into your Raspberry Pi(Mac/Linux). If you are a Windows user you need to use Putty

ssh pi@the-ip-address-of-the-pi  

The default username and password of the Raspbian install is.

user: pi

password: raspberry

Installing Node.js

Downloading Node.js(NPM ships with it)

wget http://node-arm.herokuapp.com/node_latest_armhf.deb  

Installing Node.js(required by Ghost)

sudo dpkg -i node_latest_armhf.deb  

Installing Sqlite required by Ghost.

sudo apt-get install sqlite3  

Installing NGINX(used to reverse proxy Ghost)

sudo apt-get install nginx-full  

Installing Supervisor(to manage Ghost)

sudo apt-get install supervisor  

Ghost setup

This will download the latest version of Ghost.

wget https://ghost.org/zip/ghost-latest.zip  

Unzipping the folder we just downloaded.

unzip ghost-latest.zip -d Ghost  

Set Ghost/ as the current directory

cd Ghost/  

Installing dependencies used by Ghost using NPM.

npm install --production  

Run the command below to see everything works fine.

npm start --production  

Time to setup turn Ghost into a service.

Creating the ghost.conf file for Supervisor to manage Ghost.

touch /etc/supervisor/conf.d/ghost.conf  

Editing the file, you can choose any editor you like.

nano /etc/supervisor/conf.d/ghost.conf  

Add these lines to the ghost.conf file.

[program:ghost]  
command = npm start --production  
directory = /home/pi/Ghost/  
user = pi  
autostart = true  
autorestart = true  
stdout_logfile = /var/log/supervisor/ghost.log  
stderr_logfile = /var/log/supervisor/ghost_err.log  
environment = NODE_ENV="production"  

Now save the file, in nano CTRL + X + Y.

You can start Supervisor, if it did not start after installing.

service supervisord start  

Now set Supervisor to run on startup.

sudo update-rc.d supervisord defaults  

Starting Ghost service we just created.

sudo supervisord start ghost  

Ghost will be running in production in port 2368.

Reverse proxying Ghost with NGINX.

Editing the default file.

nano /etc/nginx/sites-enabled/default  

Add these lines

server {  
        listen 80; 
        server_name yourdomain.com; # Change this to your hostname

        location / {
        proxy_pass       http://127.0.0.1:2368;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr;
        }

    }

Save the file

Now restart NGINX.

service nginx restart  

Now visit your Raspberry Pi ip address. You will be presented with a beautiful setup screen.

You can edit the Ghost hostname and other settings by editing the config.js stored in the Ghost folder.

Services like DynDNS can be used to manage hostname, if you want your Ghost blog to be public and use a domain name instead of the ip address.

If you have any questions or problem, leave a comment below.

rTorrent on Raspberry Pi

rTorrent is a command line ncurses BitTorrent client written in C++, based on the libTorrent. rTorrent is very lightweight and has a very clean command line user interface. rTorrent is also one of the most lightweight BitTorrent clients used by most of the BitTorrent distribution servers. rTorrent is a really good BitTorrent client for Raspberry Pi. rTorrent is lighter and faster compared to BitTorrent clients like Transmission, Deluge and takes lesser CPU resource.

rTorrent performs better on the tests I have done on my Raspberry Pi. The Raspberry Pi I have been using is a Model B.

Let’s get started

Updating your local repository database.

sudo apt-get update  

Installing screen and rTorrent. If you are a Tmux user you can go ahead and use it instead of screen.

sudo apt-get install screen rtorrent  

Now create a rtorrent.rc file.

touch ~/.rtorrent.rc  

Open the file in nano and add the example config below.

nano ~/.rtorrent.rc  

Here is an example config of .rtorrent.rc.

# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
#max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
#max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
#max_uploads = 15

# Global upload and download rate in KiB. "0" for unlimited.
#download_rate = 0
#upload_rate = 0

# Default directory to save the downloaded torrents.
directory = /the/place/where/the/torrent/will/be/stored/

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
#session = ./session

# Watch a directory for new torrents, and stop those that have been
# deleted.
#schedule = watch_directory,5,5,load_start=./watch/*.torrent
#schedule = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
#schedule = low_diskspace,5,60,close_low_diskspace=100M

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
port_range = 6890-6999

# Start opening ports at a random position within the port range.
port_random = yes

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
check_hash = yes

# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
# 
# dht = auto

# UDP port to use for DHT. 
# 
# dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the maincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 5

You can edit the .rtorrent.rc as per your needs.

Now we can start using rTorrent.

screen rtorrent  

You can detach to the rtorrent screen by typing CTRL + A + D.

To connect back to the rTorrent screen.

screen -r   

To add a BitTorrent simply hit ENTER

Now you have you rTorrent running on your Raspberry Pi. If you have any question feel free to leave a comment below.

BitTorrent Server on Raspberry Pi

Here is a really easy process to turn your Raspberry Pi into a high performance Bit-torrent server that can be used to download or upload Bit-torrent. Using Raspberry Pi as a BitTorrent can be good for users who are using more than one OS or hardware or prefer to download their stuff in the background while doing any other work. It can also be useful if you want to access all your BitTorrent in one place without changing hardware.

We would be using Transmission daemon as our BitTorrent client as it is very lightweight and comes with a really nice Web UI. We will be reverse proxy Transmission daemon using Nginx as it lets give performance benefits. This tutorial is for Debian based Linux distributions for Raspberry Pi like Raspbian or if you prefer minimal build I would recommend the Raspbian-UA-Netinst. Lets get started.

Installing.

If you are root user you don’t require to have sudo before every command.

  • Updating local package database.

    sudo apt-get update

  • Installing Transmission daemon.

    sudo apt-get install transmission-daemon

  • Installing Nginx.

    sudo apt-get install nginx-full

  • Stopping Transmission Daemon to write changes in settings.json file.

    service transmission-daemon stop

  • Editing settings.json that is located in /etc/transmission-daemon/settings.json.

    nano /etc/transmission-daemon/settings.json

You configuration file should look something like this.

{  
    "alt-speed-down": 15,
    "alt-speed-enabled": false,
    "alt-speed-time-begin": 540,
    "alt-speed-time-day": 127,
    "alt-speed-time-enabled": false,
    "alt-speed-time-end": 1020,
    "alt-speed-up": 15,
    "bind-address-ipv4": "0.0.0.0",
    "bind-address-ipv6": "::",
    "blocklist-enabled": true,
    "blocklist-url": "http://blacklistedsite.com",
    "cache-size-mb": 4,
    "dht-enabled": true,
    "download-dir": "/home/pi/Downloads",
    "download-limit": 100,
    "download-limit-enabled": 0,
    "download-queue-enabled": true,
    "download-queue-size": 5,
    "encryption": 1,
    "idle-seeding-limit": 30,
    "idle-seeding-limit-enabled": false,
    "incomplete-dir": "/media/NASDRIVE/Torrent_inprogress",
    "incomplete-dir-enabled": true,
    "lpd-enabled": false,
    "max-peers-global": 200,
    "message-level": 2,
    "peer-congestion-algorithm": "",
    "peer-limit-global": 240,
    "peer-limit-per-torrent": 60,
    "peer-port": 51413,
    "peer-port-random-high": 65535,
    "peer-port-random-low": 49152,
    "peer-port-random-on-start": false,
    "peer-socket-tos": "default",
    "pex-enabled": true,
    "port-forwarding-enabled": true,
    "preallocation": 1,
    "prefetch-enabled": 1,
    "queue-stalled-enabled": true,
    "queue-stalled-minutes": 30,
    "ratio-limit": 2,
    "ratio-limit-enabled": false,
    "rename-partial-files": true,
    "rpc-authentication-required": true,
    "rpc-bind-address": "0.0.0.0",
    "rpc-enabled": true,
    "rpc-password": "{46949fbf39bfeec6dc9d4bff9f40c3f52219a4260yk9yGNo",
    "rpc-port": 9091,
    "rpc-url": "/transmission/",
    "rpc-username": "transmission",
    "rpc-whitelist": "127.0.0.1",
    "rpc-whitelist-enabled": false,
    "scrape-paused-torrents-enabled": true,
    "script-torrent-done-enabled": false,
    "script-torrent-done-filename": "",
    "seed-queue-enabled": false,
    "seed-queue-size": 10,
    "speed-limit-down": 100,
    "speed-limit-down-enabled": false,
    "speed-limit-up": 100,
    "speed-limit-up-enabled": false,
    "start-added-torrents": true,
    "trash-original-torrent-files": true,
    "umask": 7,
    "upload-limit": 100,
    "upload-limit-enabled": 0,
    "upload-slots-per-torrent": 14,
    "utp-enabled": true
}

You can change the configuration as you prefer to suite your needs. It is a really simple JSON document that can be edited really easily and can do many performance differences. I would recommend that you should change the rpc-username, rpc-password string and disable rpc-whitelist-enabled If you wan’t all ip address to access the Transmission Daemon. The most important thing to change is rpc-bind-address. change it from

"rpc-bind-address": "0.0.0.0",  

to

"rpc-bind-address": "127.0.0.1",  

This will let Transmission daemon run on 127.0.0.1 instead of make it run on the external ip address and makes slow as it has needs to first known the IP and then run it. Next is reverse proxy it using NGINX. For that we can edit the default located in /etc/nginx/site-enabled/default. Replace the file content with this.

server {  
        listen 80; 

        location / {
        proxy_pass       http://127.0.0.1:9091;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr;
        }

} 

Now start Nginx.

service nginx start  

Lets start transmission daemon.

service transmission-daemon start  

Now you have Transmission daemon running on port 80 of your Raspberry Pi address. Visit your Raspberry Pi IP address and you should have the Transmission Web UI waiting for you to add a new BitTorrent. The amount of BitTorrent you download also depends on the SD card size. It is recommended that you use an external HDD to serve storage purpose.

Thanks for reading. If you have any question feel free to leave a comment below.

Docpad on Raspberry Pi

Docpad is an open source static document/website generator written in Node.js, Docpad lets you choose the way it builds static documentation/website with the help of plugins, Docpad has a build in plugin manager that uses NPM to install node modules that are used by Docpad and required by plugins as dependencies, Some plugin makes Docpad a really good choice if you are planning to choose Node.js based mediums to build your website, plugins like marked which is a markdown interpreter let you write your pages in markdown, Docpad also lets you choose the templating engine, If you prefer Jade you can use Jade to template, If you prefer Eco a recommended templating engine by Docpad developer, you can go ahead or if you like Handlebars you can go ahead and install that plugin and start templating in Handlebars.

Docpad main configuration file is written in Coffee Script. Docpad lets you set collections that can be listed so you can build multi-blog site using Docpad.

Since Docpad is written in Node.js and is a NPM module that can be installed as a global package on your system. It’s really easy to install Docpad on Raspberry Pi.

Let’s get started.

  • Installing Node.js on our Raspberry Pi here, if you already have Node.js installed on your system you can skip this step.
  • Installing Docpadnpm install docpad -g

Once you have successfully installed Docpad you can go ahead and run docpad run.

docpad run  

Now docpad run will list the skeletons available for creating a website.

You can choose no skeleton if you want to build your Docpad project from scratch.

Plugins can be installed by running

docpad install  # example `docpad install marked`  

Now your Raspberry Pi has been turned into a static website generator. If you have any questions feel free to leave a comment below.

Wintersmith on Raspberry Pi

Wintersmith is a open source flexible static website generator writen in Node.js that uses Jade for templating and Marked.

Jade is a simple and easy to use templating engine that supports complete HTML markup and uses indent to nest a specific tag in or out of another tag. Marked is a Markdown parser that supports GitHub Flavoured Markdown. Wintersmith stores it’s preferences and settings in a config.json file. Wintersmith is faster than most of the popular static website generator, Wintersmith can gain more functionality when plugins are added by default, Wintersmith ships with paginator.coffee plugin that lets you paginate your posts. Wintersmith is also very lightweight which makes it a winner for the Raspberry Pi in the static website world.

We can begin by installing Wintersmith by following a few simple steps.

Installing Node.js on Debian based Linux distribution for Raspberry Pi (Raspbian, PiBang).

Downloading

wget http://node-arm.herokuapp.com/node_latest_armhf.deb  

Installing

sudo dpkg -i node_latest_armhf.deb  

Installing Node.js on Arch Linux ARM for Raspberry Pi.

sudo pacman -Sy nodejs  

Installing on Fedora based Linux distribution for Raspberry Pi (Fedora ARM, Pidora).

sudo yum install node npm  

Once you are done installing Node.js on your Raspberry Pi, we can now go ahead and successfuly install Wintersmith.

sudo npm install -g wintersmith  

We now have Wintersmith installed on our Raspberry Pi.

You can now create you first Wintersmith based website.

wintersmith new Blog  

Now you can enter the directory.

cd Blog/  

We can load the preview web server that comes built-in in Wintersmith.

wintersmith preview  

We can alslo build the output files.

wintersmith build  

To customise your website edit the config.json.