Mono server for ASP.NET

#install mono server
sudo apt-get install mono-fastcgi-server4

Add following to /etc/nginx/fastcgi_params
fastcgi_param PATH_INFO "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Nginx configuration
server {
listen 80;
server_name [HOST_NAME];

location / {
root [APP_ROOT];
index index.html index.htm default.aspx Default.aspx;
fastcgi_index Default.aspx;
include /etc/nginx/fastcgi_params;

Restart Nginx
sudo service nginx restart

Start mono server
fastcgi-mono-server4 /applications="[HOST_NAME]:/:[APP_ROOT]" /socket=tcp:
e.g. fastcgi-mono-server4 /applications="" /socket=tcp:

Mono Server initialization script

# Provides:
# Required-Start: $local_fs $syslog $remote_fs
# Required-Stop: $local_fs $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start fastcgi mono server with hosts


MONOSERVER=$(which fastcgi-mono-server4)
MONOSERVER_PID=$(ps auxf | grep fastcgi-mono-server4.exe | grep -v grep | awk '{print $2}')


case "$1" in
if [ -z "${MONOSERVER_PID}" ]; then
echo "starting mono server"
${MONOSERVER} /applications=${WEBAPPS} /socket=tcp: &
echo "mono server started"
echo ${WEBAPPS}
echo "mono server is running"
if [ -n "${MONOSERVER_PID}" ]; then
echo "mono server stopped"
echo "mono server is not running"

exit 0

Add appropriate rights:
chmod +x /etc/init.d/monoserve

And install the script:
update-rc.d monoserve defaults

Share a web page on social media platforms

Recently I was working on a site that required the main page to be shared via lots of different social media platforms. Here are some of the urls I used. Customise the url and use it with any page on your website for each social media platform.

Share on…


Facebook Feed



Google Plus"



These can be added to any hyperlink and the link customised to look how you would like e.g.

facebook share button

Here is an extra tip. If you want to see how a particular url will display as a Facebook share, check out the Facebook debug tool

Capistrano3-nginx permissions

Capistrano3 has a plugin for Nginx called capistrano3-nginx which allows you to manage it using the cap command or through your deployment scripts e.g. nginx:reload

However, if you try to run any of these command on some systems, it may start to complain about not having permissions or your deploy my hang while asking for a sudo password.

To get round this you need to give the deploying user the permissions to run a sudo command without needing a password. If you’re like me the, the first time you hear that you think “that can’t be very secure”. Correct! Giving any user full sudo access without a password isn’t recommended.

To improve things we can restrict what commands the deploying user can run as sudo without a password. To do this edit the sudoers file using the following command

sudo visudo

Adding the following line will then allow the deploying user to run the require Nginx commands without the need for a password.

deploy ALL=NOPASSWD:/usr/sbin/service nginx *

You may need to adjust the Nginx service path if your set up is different. The ‘*’ just allows all commands on the Nginx service. You could restrict this further by only allowing specific commands like ‘restart’.

Once you have saved the changes you should be able to run Nginx service commands without the need to enter a password and Capistrano should in turn be able to do the same.

EC2 Ubuntu unable to resolve host

During setup of an Ubuntu server on EC2 I was getting a warning like this:

sudo: unable to resolve host ip-xx-xx-xx-xx

To resolve this I used the following command to append a localhost entry for the hostname to the hosts file

echo " $HOSTNAME" | sudo tee -a /etc/hosts

locale settings warning on Ubuntu

Every time I set up a new Ubuntu instance on EC2 I get locale warnings during updates. The problem is that locale settings are not configured by default. To set them do the following:

List your locale details

Generate the required locale settings
sudo locale-gen en_US.UTF-8

Reconfigure the locales package
sudo dpkg-reconfigure locales

Some installations may also require you to output the locale settings to the environment variables by appending the following to the /etc/environment file:

Postgresql. Failed to build gem native extension. pg gem.

I have been trying to deploy a rails app with capistrano and bundler and kept getting the “Failed to build gem native extension” error. After installing, probably, many unnecessary packages, I finally came across a post which pointed me in the right direction.

It turns out that the default pg_config location did not match the path that capistrano was using. I found this by doing
which pg_config
on the server and comparing it to the command which was being executed in the trace.

Since they didn’t match I found a command to set the global local variable for pg_config.
bundle config --with-pg-config=/usr/bin/pg_config

Once run, bundler executed successfully while deploying.

WARN Could not determine content-length of response body. PATCH

Have had this notice from Webrick for a while and previous response was just “it’s not harming anything, just ignore it”.

Thankfully someone wasn’t happy with that answer and went looking for the source of the problem.

Edit the httpresponse.rb around line 205.
if chunked? || @header['content-length']
if chunked? || @header['content-length'] || @status == 304 || @status == 204

Here is the patch

Unfortunately if you are using rvm or rbenv you need to change each instance of Webrick. e.g.

Keep ssh connect alive

When programming my Raspberry Pi I often go and research something while connected to the Pi via ssh. Sometimes if left for too long the ssh will disconnect and i will have to restart to get a new connection

Here is a setting I have used to keep the ssh connection live while not being used.

Add this line to the end of /etc/ssh/ssh_config
ServerAliveInterval 60

Adding custom countries using Carmen in rails

I had been using a gem to give me countries for an app i’ve been doing but needed to create some custom country data. The gem didn’t support custom data so I went on the search and found a gem called Carmen, made even easier for my rails project by carmen-rails gem.

Once installed I added carmen.rb to my config/initializers/ folder
Carmen.append_data_path File.expand_path('../../', __FILE__)

Then added world.yml to config/ folder
- alpha_2_code: ND
alpha_3_code: NID
numeric_code: "999"
type: country

Then updated config/locales/en.yml
name: New country

Now I can reference
Carmen::Country.named('New Country')

Python script to test IO with WiringPi GPIO on Raspberry Pi

The last week or so I have been playing about with the Raspberry Pi and Picoborg. After running the Picoborg install script I created the following script to test that it was working.

import RPi.GPIO as GPIO # import GPIO library
import time # import time library
GPIO.setup(4, GPIO.OUT) # 4 is the pin reference for first IO
GPIO.output(4, GPIO.LOW) # LOW turns IO off so this makes sure it's off to start
GPIO.output(4, GPIO.HIGH) # turn IO on
time.sleep(1) # wait 1 second
GPIO.output(4, GPIO.LOW) # turn IO off
GPIO.cleanup() # tidy up

This can be run by:
sudo chmod +x
sudo python