run Retroshare headless on a server

This sounds easy but for some reason it took like days to figure out how to do this. Maybe someone else struggles with Retroshare on servers as well.

Retroshare is a relatively young project that aims to offer an Open Source cross-platform, private and secure decentralized communication platform to their users.

Retroshare has some really good concepts. As every software, it is not totally bug-free. :) It uses less resources than other Friend-To-Friend-network clients. On a vserver, it can help the clients not to lose all friends' IP's (what would cause manual adjustment) and it could serve your F2F network with popular files so that users uplinks stay chilled.

Let's assume you have a server with a working X11-forwarding to your machine. If you have another distribution than Debian please beware of commands that are distribution specific. Further, make sure you have the dependencies installed:

aptitude install libqt4-dev libgpgme11-dev libgpg-error-dev libupnp-dev \
  libssl-dev g++ make

Since the nogui-version of Retroshare did not work for me (starts, runs, logs but does not connect), I installed xvfb (a virtual X-Server) to be able to start the GUI-version of Retroshare detached in the background.

aptitude install xvfb

For security reasons, create system user account for Retroshare with a home directory and set a reasonable password.

useradd -m retroshare
passwd retroshare

Login as retroshare (hint: using su is likely to break X11 forwarding).

Install the latest stable Retroshare client according to the Retroshare wiki.

cd <SRC_DIR>/retroshare-nogui/src
qmake && make
chmod +x retroshare-nogui
mv retroshare-nogui ~/retroshare-nogui

Connect to your server with X11-forwarding enabled. I suggest copying your ~/.gnupg directory to the server to have the same certificate and friends. Start Retroshare, configure it (enabling auto login is necessary!) and add your friends so you see the client on the server connected to your F2F network.

Once this worked you can start your backgrounded Retroshare! I use the following script:

#!/bin/bash
# file ~/retroshare_quiet_up.sh
if [ `top -bn1|grep -c RetroShare` -gt 0 ];
then
  echo "RetroShare is already running..."
else
  nice -n15 xvfb-run ./RetroShare &>/dev/null &
fi
exit

I suggest to observe Retroshares presence and restart it daily (it seems to leak memory). So hack in:

crontab -e

and add:

# check if Retroshare is running every 10 minutes
*/10 * * * * ~/retroshare_quiet_up.sh >/dev/null 2>&1

# kill Retroshare once a day, will be restarted by job above
0 5 * * * killall RetroShare

That's all.