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
Shell
1
mono-service2 something.exe
To stop a service
Shell
1
kill`cat/tmp/something.exe.lock`
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.
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.
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:
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 …
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
After a bit of research I found a product called GateOne that would enable me to use a web browser to connect to ssh using standard https – cool!
Install GateOne
Shell
1
2
3
4
5
6
7
sudo apt-getinstall python-setuptools
git clonehttps://github.com/liftoff/GateOne.git
cdGateOne
sudo python setup.pyinstall
cd..
sudo rm-rf GateOne
sudo gateone
Then ctrl+c so we can edit the config
edit config
Shell
1
sudo vi/etc/gateone/conf.d/10server.conf
at the end of the line with origins, add the IP of the Pi, i.e. , “192.168.0.123” then restart the daemon:
restart daemon
Shell
1
sudo/etc/init.d/gateone restart
to check it out browse to https://192.168.0.123/
All that remains is to ensure it starts automatically on reboot – I think the update-rc.d script must be a bit buggy on the Pi. I ended up doing all of this as I was having some trial and error fun:
start automatically
Shell
1
2
3
4
sudo update-rc.dgateone defaults
sudo update-rc.dgateone start202345.stop80016.
cd/etc/rc2.d/
sudo mvK01gateone S01gateone
Next up – some authentication …
within /etc/gateone/conf.d/20authentication.conf the authenication type was changed to google
authentication
Shell
1
"auth":"google",
and the terminal configuration (/etc/gateone/conf.d/50terminal.conf) was modified to turn off the terminal for all users (allow: false) and then add it back on just for me:
"commands":{"SSH":{"command":"/usr/local/lib/python2.7/dist-packages/gateone-1.2.0-py2.7.egg/gateone/applications/terminal/plugins/ssh/scripts/ssh_connect.py -S '%SESSION_DIR%/%SESSION%/%SHORT_SOCKET%' --sshfp -a 'oUserKnownHostsFile=\\\"%USERDIR%/%USER%/.ssh/known_hosts\\\"'","description":"Connect to hosts via SSH."}},
"commands":{"SSH":{"command":"/usr/local/lib/python2.7/dist-packages/gateone-1.2.0-py2.7.egg/gateone/applications/terminal/plugins/ssh/scripts/ssh_connect.py -S '%SESSION_DIR%/%SESSION%/%SHORT_SOCKET%' --sshfp","description":"Connect to hosts via SSH."}},
"default_command":"SSH",
"dtach":true,
"enabled_filetypes":"all",
"environment_vars":{"TERM":"xterm-256color"},
"session_logging":true,
"syslog_session_logging":false,
"allow":true
}
}
}
Back in /etc/gateone/conf.d/10server.conf I added my external dns to the list of allowed origins and forwarded port 443 on my router to my Pi
After downloading the latest wheezy image from the raspberry pi site and flashing it onto the SD card using Win 32 Disk Imager I transferred the card into the Pi and powered it on. To use my approach it must have both the WiFi usb adaptor and an ethernet cable plugged in.
I then go to my router’s admin page and take a look to see what IP address has been allocated to the Pi’s ethernet link.
Then, using Putty, connect to the ssh using the credentials username: pi password: raspberry (all lowercase).
Once on, the following command were run:
Configure wifi
Shell
1
2
3
sudo apt-getupdate
sudo apt-getinstall wicd-curses
sudo wicd-curses
Then navigate down (using the arrow keys) to my home network, then use the right arrow key to go and configure it. The only thing I put in the configuration was the setting to “Automatically connect” and the key to the network – then pressed F10 to save the config, the Q to quit.
Having done all that I shutdown the pi, unplug the ethernet cable and power it back on.
shutdown
Shell
1
sudo shutdown-hnow
Back in my router’s admin page I can find out the new IP address of the Pi (and reserve it for future if I want).