Hackviking He killed Chuck Norris, he ruled dancing so he took up a new hobby…

20May/160

BtSync: Refuses to connect to any peers

Have a few ARM based nodes running BitTorrent Sync (btsync) and needed to re-install one of them. Trying to remove it I ended up with my main node (owner) for all my folders to stop connecting to peers or accepting incoming connections. Took me a while to figure out a solution and I couldn't find much about it on the forums or when I googled so I thought I'll share this quick story.

Background

This applies, in my case at least, to the distribution installed via apt-get from YeaSoft. After reading a forum thread about how to remove old and abandoned peers I decided to set the peer_expiration_days setting to 0 to clean the old peer out. So I used the dpkg-reconfigure btsync command and set it to 0. The old peers where cleaned out so I went back to revert the config back to it's original. In the "wizard" it stated that leaving it blank would render the default value of 7 days. So I removed the 0 and saved the configuration. This might have been a mistake on my part but the configuration tool actually seems broken in this distribution.

Error

After doing that I could not set the value via dpkg-reconfigure btsync to anything else and no peers could connect or where contacted. Right after recycling the daemon they showed up for a few seconds and then disconnected. Since I'm running the free, unlicensed version, I can't switch owner of the folders so I had to get this online again. Changing config files didn't matter since they were, as stated in them, overwritten every time the daemon started again.

Solution

Finally I downloaded the latest version from the getsync.com website and unpacked it in the temp folder. Looking at the command line used in the /etc/init.d/btsync script I could find what config file it used. So I started the latest version, which have support for "power user options" in the UI, with the same config file parameter. Went in to the UI and changed the peer_expiration_days back to it's original value, there even is a reset value link. Then shot down the process and started the original daemon with init.d and order where restored.

Tagged as: No Comments
3Apr/160

Pi: Geo-location backup with BtSync

Building a geo-location backup for your NAS is a good idea! To spread the risk over two or more locations increases your backup value a lot. Most people confuse redundancy and backup. If you only have a USB-disk backup of your NAS it only protects you against hardware failure. If there is a fire or a break in you will still lose your data. A lot of people take a USB-disk to a second location, like their office, to mitigate this problem. But to be honest how often will that backup be done if you have to remember to bring the disk back and forth? We want automatic backups to our offsite location, in this case my office. So we are going to build a BitTorrent Sync "satellite"
Continue reading...

11Mar/160

BtSync: Let my NAS sleep

BitTorrent Sync (btsync) will re-index all files every 10 minutes to look for new files to sync. After installing btsync on Raspberry Pi initially and then ending up running it on an Odroid-C1 my WD NAS never sleeps. The first 48 hours it was expected since it took all that time to index all the files. But now my NAS never sleeps. Since this is a backup solution I don't have the need for it to actually re-index every 10 minutes. If the Western Digital LiveBook Duo is left alone for 20 minutes it will spin down it's hard drives. So here is a quick guide on how to configure the re-index interval for btsync installed on an arm system. This is done on the system initially installed with the Raspberry Pi: BitTorrent Sync guide.

Continue reading...

10Mar/160

Raspberry Pi: BitTorrent sync alternative Syncthing

Btsync is a great tool for syncing data and backups to several different locations. By leveraging the torrent technology you can increase the download/upload speeds by adding more nodes to the swarm. Installing Btsync on a built in system like the Raspberry Pi or Odroid-C1 is a challenge since it consumes a lot of system resources, read more about installing BitTorrent Sync on Raspberry Pi. Reading up on the subject a lot of people did suggest that Syncthing takes up less system resources then btsync so let's install it and try it out.

Pre requirements

Same as for the btsync install I need to access my NAS root NFS share to get all the data that I will sync. So first I setup a mount point and do a persistent mount of that share.

sudo mkdir /mnt/stroot
sudo chmod 777 /mnt/stroot

Then let's edit /etc/fstab so run sudo nano /etc/fstab and add a line representing your share.

192.168.0.5:/nfs /mnt/stroot nfs rsize=8192,wsize=8192,timeo=14,nolock,intr 0 0

This will give me the root for all the shares so I don't have to map every share individually but are able to access all of them as subfolders.

To test this out we can run sudo mount -a. Then reboot the system and check that the mount is persistent. If you have issues with the persistence and are running DHCP please see my Raspbian:fstab doesn't mount NFS on boot article for reference.

Install

Download the Syncthing repository key and add it.

wget -O - https://syncthing.net/release-key.txt | sudo apt-key add -

Add the repository

echo "deb http://apt.syncthing.net/ syncthing release" | sudo tee /etc/apt/sources.list.d/syncthing.list

Update the repository with sudo apt-get update and then install with

sudo apt-get install syncthing

Then try to run it with syncthing, as soon as you see it start properly you can stop it with CTRL + C. To set it up to run as a service we need first reconfigure the bind address.

nano /home/pi/.config/syncthing/config.xml

Look for the gui option, it should look like this:

<gui enabled="true" tls="false">
<address>127.0.0.1:8384</address>
<apikey>2Yy41r5k5oocz6rDIWVsKeP4wUx9uknD</apikey>
<theme>dark</theme>
</gui>

Here you can change all the settings in regard to the UI. Change the bind address to 0.0.0.0 so it will respond to all ip addresses. If your running on a fixed IP and not DHCP you can go ahead and bind it to a specific address if you like. You can also change the tls setting to true, enabling https for the UI. This will however result in a security warning when you browse to the UI due to the self signed certificate.

If you now run syncthing from the command line it will bind to the IP and you will be able to navigate to the UI.

Autostart Syncthing as a "service"

First we need to create a init.d script for Syncthing.

sudo nano /etc/init.d/syncthing

Copy and paste the following into it:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          Syncthing
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Syncthing
# Description:       Syncthing is for backups
### END INIT INFO
 
 
# Documentation available at
# http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html
# Debian provides some extra functions though
. /lib/lsb/init-functions
 
 
DAEMON_NAME="syncthing"
DAEMON_USER=pi
DAEMON_PATH="/usr/bin/syncthing"
DAEMON_OPTS=""
DAEMON_PWD="${PWD}"
DAEMON_DESC=$(get_lsb_header_val $0 "Short-Description")
DAEMON_PID="/var/run/${DAEMON_NAME}.pid"
DAEMON_NICE=0
DAEMON_LOG='/var/log/syncthing'
 
[ -r "/etc/default/${DAEMON_NAME}" ] &amp;&amp; . "/etc/default/${DAEMON_NAME}"
 
do_start() {
  local result
 
	pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" &gt; /dev/null
	if [ $? -eq 0 ]; then
		log_warning_msg "${DAEMON_NAME} is already started"
		result=0
	else
		log_daemon_msg "Starting ${DAEMON_DESC}" "${DAEMON_NAME}"
		touch "${DAEMON_LOG}"
		chown $DAEMON_USER "${DAEMON_LOG}"
		chmod u+rw "${DAEMON_LOG}"
		if [ -z "${DAEMON_USER}" ]; then
			start-stop-daemon --start --quiet --oknodo --background \
				--nicelevel $DAEMON_NICE \
				--chdir "${DAEMON_PWD}" \
				--pidfile "${DAEMON_PID}" --make-pidfile \
				--exec "${DAEMON_PATH}" -- $DAEMON_OPTS
			result=$?
		else
			start-stop-daemon --start --quiet --oknodo --background \
				--nicelevel $DAEMON_NICE \
				--chdir "${DAEMON_PWD}" \
				--pidfile "${DAEMON_PID}" --make-pidfile \
				--chuid "${DAEMON_USER}" \
				--exec "${DAEMON_PATH}" -- $DAEMON_OPTS
			result=$?
		fi
		log_end_msg $result
	fi
	return $result
}
 
do_stop() {
	local result
 
	pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" &gt; /dev/null
	if [ $? -ne 0 ]; then
		log_warning_msg "${DAEMON_NAME} is not started"
		result=0
	else
		log_daemon_msg "Stopping ${DAEMON_DESC}" "${DAEMON_NAME}"
		killproc -p "${DAEMON_PID}" "${DAEMON_PATH}"
		result=$?
		log_end_msg $result
		rm "${DAEMON_PID}"
	fi
	return $result
}
 
do_restart() {
	local result
	do_stop
	result=$?
	if [ $result = 0 ]; then
		do_start
		result=$?
	fi
	return $result
}
 
do_status() {
	local result
	status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}"
	result=$?
	return $result
}
 
do_usage() {
	echo $"Usage: $0 {start | stop | restart | status}"
	exit 1
}
 
case "$1" in
start)   do_start;   exit $? ;;
stop)    do_stop;    exit $? ;;
restart) do_restart; exit $? ;;
status)  do_status;  exit $? ;;
*)       do_usage;   exit  1 ;;
esac

Make the init.d script executable and make it start on boot.

sudo chmod +x /etc/init.d/syncthing
sudo update-rc.d syncthing defaults

Now you can start the Syncthing service like any other service.

sudo service syncthing start

Conclusion

The reason I looked into Syncthing in the first place was the memory consumption of btsync. After running a few tests I can see that it's the same with Syncthing. By the time I'm writing this my btsync instance running on my Odroid-C1 has index almost 4Tb of data and is running smoothly. Syncthing is opensource, which I like a lot, but it's a much more immature product then btsync. The windows client is just an .exe that will run a local web server that you connect to. Btsync seems more mature and robust from my initial tests. Syncthing will probably develop into something better but at this time I will go with btsync instead. Btsync is also developed by the torrent technology creators which make me believe in it even more. Install guide for btsync...

Why don't you install both of them and try them out and let me know what you think in the comments?

9Mar/160

Odroid: Swap on USB-stick

Swap is used when the kernel runs out of memory and need to swap less used information to the disc to make space for information currently in use. In a good setup the swap will never be used but if it's needed and not existing it will make processes crash.

I have just started out testing BitTorrent Sync (btsync) on my Odroid-C1 and noticed that all the memory was allocated more or less straight away after starting the btsync service. So just to be safe during my test, to avoid crashes, I added a 8Gb USB stick to use for swap space. You can of course use the SD-card but that will take up space needed for the system as well as shorten the life of your SD-card.

Continue reading...

8Mar/160

Raspberry Pi: BitTorrent Sync

BitTorrent is not only pirated movies and tv-shows it's an actual technology for moving large amounts of data between several nodes at once. There are several applications for this sync technology. Large companies like Facebook use it to sync new releases among all their production servers for example. If three or more nodes are syncing the same content it will increase the sync speed since it's a non centralized technology. All the clients will help to seed the data they already have which will make the sync go faster and faster the more nodes the data propagates to.

Btsync will make use off all the memory available in your Raspberry Pi so I recommend running this on it's own. I have tested this out on both a Raspberry Pi 2 B and the older Raspberry Pi B and they more or less run the same. It will take some time to index all your data but when testing it on a regular windows pc it was pretty slow as well. Continue reading...