Working with mono-service on a raspberry pi

I was working with on a .net service that I wanted to run on my raspberry pi.  Initially this was fairly easy but then I wanted to run it on startup as a service.

After a bit of digging I found out about mono-service and mono-service2 (for .net 1 and .net 2 respectively)

Working with this is as simply as …

To start a service

To stop a service

Woah – ok stopping isn’t so straightforward …

Basically when the service starts it puts a lock file in the /tmp folder.  This is just a text file that contains the process id (pid) of the exe that is running.  By doing the cat, and passing that to kill, the service will stop.

Next up was to get it to run on start up.

I found a useful bash script to start, stop and restart the service … http://www.geekytidbits.com/start-stop-daemon-with-mono-service2/

Unfortunately this didn’t work immediately for me as my version of linux was built differently and didn’t have some of the parts this script depended on.

My finished script now looks like this:

This was put in \etc\init.d\bpi.sh and I did a chmod to make it match the others in that directory.

Note that there are a couple more parameters to our start command … -l to tell it where to put the lock file and -d to give it a start directory (my application writes logs and they would appear in funny places without this).

Finally the following command sets things up to start and stop in different runlevels:

sudo update-rc.d bpi.sh defaults

 

Creating tasks in Outlook from an external data source

I’ve had this script for many years but currently I don’t have a use for it so I’m getting rid of it but putting it here for future reference in case I need it again.

It’s got code to retrieve data from a database and convert it to a tab delimited string.  There’s more code which then parses this into tasks.  The upshot of this is that I’ve used it in the past to take data from the clipboard (having come from excel).

The code has been anonymised which will have introduced a bug or two but the gist of it is valid.

 

Determine the installed version of .net framework

Just making a quick reference for myself of the info found on msdn.

Take a look at the following registry keys

Frameworks 1 – 4
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP

Frameworks >= 4.5
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Release
where
378389 = .NET Framework 4.5
378675 = .NET Framework 4.5.1 installed with Windows 8.1
378758 = .NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2
379893 = .NET Framework 4.5.2

TFS: automating pending change set reminder emails

As an admin of a TFS server I wanted to be able to send an email to people reminding them of any pending changes they may have.
I knocked up a quick application and have now configured it to run once a week with a scheduled task.

The main logic to get pending change sets is (where _vcs is a VersionControlServer from the Microsoft.TeamFoundation.VersionControl.Client namespace):

The PendingChange class is a simple POCO:

After that it was a simple case of looping through the PendingChanges List<> building up emails and sending them.

 

Find a SharePoint feature with PowerShell

As I keep having to figure this out every time I come to do it I’m leaving it here for reference.

To find a SharePoint feature when you only know part of the name of it the following command can be used:

 

VPN goes mainstream

I’m beginning to hear a lot more about VPN’s (personal use for anonymity) in the press and I’m a bit worried it’s not understood enough.

Sales pitch: Get a VPN and your internet anonymity is restored.
Truth: It can be, but you have to be careful.

Other people will know more than me – there more than likely will be more to worry about than this. My main concern: cookies.

You get a lovely new vpn and then you use the same browser and user account to get on the net. BAM! You’re not anonymous any more!

A lot of the VPN providers sell the fact that it’s good for internet cafes. This is partly true – it will stop the others on the same wifi from snooping.  The problem is that as soon as you log on to Facebook via your VPN you’re not anonymous.  These are two different uses for a VPN and they’re not compatible.  If you’re looking for anonymity what are you doing on a social network?!  Scared of your ISP?  You should be just as scared of any website you need to log on to!

My steps for a nice clean VPN:

  1. Get a VPN service (don’t use it yet!)
  2. Set up a fresh windows user account (some may say this is overkill but it’s saved me a few times.  If you have a separate windows account then you don’t have to worry about your normal browser accidentally being opened and sending cookies.)
  3. login to that user account and download firefox as the first thing you do
  4. From now on, when on your VPN, only use your new windows account and firefox as your browser
  5. Change the cookie settings to never allow cookies from a third party site (I’ve gone a bit further than this and ban all cookies and only re-enable source-cookies if I have a specific problem)
  6. Install the NoScript firefox addon
  7. Now you can start using your VPN
  8. Never log on to any site – if you must log on to some sites then:
    1. get a new anonymous email account that is unrelated to everything else
    2. use that account for everything while you’re on your VPN
    3. never use those accounts while not on your VPN

All for now …

 

Clone a web application

I needed to set up a new web application that was a copy of an existing web application. The constraint was that there was only one farm available to work with (I did have other farms but they were running different versions of SQL server).

Approach 1
I’ll first point out that this didn’t work, skip ahead if you’re not interested.
I went through the following steps:

  1. perform a SQL backup of the content database
  2. restore the backup into a new database
  3. created a new web application
  4. marked the content database that this created as offline
  5. attached the cloned database to the web application with the powershell command Mount-SPContentDatabase – I was sure to pass in the -AssignNewDatabaseId parameter

The result was the database attached but it had no site collections in it.

It turns out that this approach could work but only if you attach it to a different farm. You can then backup that database and restore/attach it back on the source farm.

As I stated at the beginning – I didn’t have the luxury of a second farm.

Approach 2
The only option left that I could think of was to backup and restore each site collection manually.
I knocked up the following powershell script to automate this and it worked …

 

Scripting new Active Directory users

I needed an easy way to create users in Active Directory.

PowerShell to the rescue … although it didn’t work out.

The PowerShell command New-ADUser depends on AD having web services enabled which is a feature that came out with 2008 R2 – needless to say the AD server I was working with didn’t have this. So I fell back to the good old fashioned command line: dsadd user.

I put together an excel with columns like this:

So for this data

The following command is generated:

This is going to save me minutes – literally minutes – every month!

Setting up node.js and MongoDB on a Raspberry Pi

I wanted to get node.js and mongoDB up and running on my pi.  I’ve got a couple of pet projects which I’m going to tackle and I’ve decided to use the MEAN stack (MongoDB, Express, AngularJS and Node.js).  The future, for now, is JavaScript and I’m looking to know enough to make informed decisions about my place in that future.

These are the steps that I followed to get it going …

First up, node.js …

Credit to: http://blog.rueedlinger.ch/2013/03/raspberry-pi-and-nodejs-basic-setup/

Before doing this step you want to check what the latest version is – go to http://nodejs.org/dist/ and browse, starting from the biggest number backwards, looking for a release that includes “linux-arm-pi” in the title.  That’s the one to use in the following code snippet, for me it was v0.10.24/node-v0.10.24-linux-arm-pi.tar.gz

add the following before “export PATH

That’s it!  Next let’s get a server running so we can make sure it’s working … create the following content in a file called nodejs.sh

then do the following to get it to run on pi boot

now for the server.js that will run our server

put the following in the server.js file

then start the server

A quick visit to http://192.168.0.123:8080 should result in a nice “Hello World” message.

Finally a bit of tidying up in /home/pi/

Next up – mongoDB

Credit to: https://github.com/RickP/mongopi and http://ni-c.github.io/heimcontrol.js/get-started.html

Note, the scons commands performs the build and will take a few hours each

add this before “export PATH

Then set up a new db and configure it to start on boot:

You can test everything went ok by launching the MongoDB shell with the command “mongo” … see the docs for more info.

Job Done!

Looking for an RSS reader

Ever since google axed their Reader product my news consumption hasn’t been the same. I tried out a few at the time and settled on theoldreader.com but I’ve come to realise that I wasn’t using it like I wanted to – google reader used to be the first thing I loaded whereas theoldreader was loaded only once a week.

I’ve made a switch to feedly to see how that goes instead – first impressions are promising – time will tell.

At the same time I tried out instapaper as I saw that feedly could add articles to that service – my trial was short and the account is now cancelled. I like the idea … but the first few articles I saved all had important images or videos embedded, not something that instapaper is targetting. I’ve resolved to use the feedly “save for later” feature and see how that goes.