Autostart on OpenELEC using systemd

Hello there! I am using a RaspberryPi with OpenELEC on it as a MediaCenter, have BTSync already running on on it, and thought about setting up syncthing for experimental purposes. Downloading, starting, connecting and syncing Files from the attached NAS: worked fine. Autostarting syncthing on boot: not as simple as I expected

OpenELEC has a autostart.sh, but due to the fact I was unable to daemonize syncthing on OpenELEC, I switched to systemd using the provided file [“etc/linux-systemd/system”][1]. I got a lot of syncthing[700]: 13:10:05 FATAL: mkdir ": read-only file system errors, and tried every possible combination of different parameters and settings within those files (searching the web did not really help) so I switched to the provided file [“etc/linux-systemd/user”][2]. That got me the error syncthing[862]: 13:38:21 FATAL: home: No home directory found - set $HOME (or the platform equivalent). although i added the parameter -home="/storage/.config/syncthing" (which is the default config-path) So i googled how to add environment variables to systemd-scripts and edited my syncthing.services file to

[Unit]
Description=Syncthing - Open Source Continuous File Synchronization
Documentation=https://github.com/syncthing/syncthing/wiki
After=network.target

[Service]
Environment="HOME=/storage/.config/syncthing"
ExecStart=/storage/syncthing/syncthing -home=/storage/.config/syncthing
Restart=on-failure
RestartPreventExitStatus=1
SuccessExitStatus=2
RestartForceExitStatus=3 4

[Install]
WantedBy=default.target

Removing either the Environment-Variable or the -home-Parameter results in syncthing not starting. Well, this works for me, but I find it kind of strange to have to provide the home-Path twice, so is this an error or expected behavior? (And I felt like posting this somewhere, so other users trying to get syncthing autostarting on OpenELEC can read it :blush:) [1]: https://github.com/syncthing/syncthing/blob/master/etc/linux-systemd/system/syncthing@.service [2]: https://github.com/syncthing/syncthing/blob/master/etc/linux-systemd/user/syncthing.service

Thanks for this it was very useful!

A while later I found another solution which might be handy for those who simply want OpenElec to run things at start-up including Syncthing, and don’t need daemonised processes:

From - http://wiki.openelec.tv/index.php?title=Autostart.sh

autostart.sh is run on system startup. It can be used to run commands before XBMC/Kodi starts. To create it simply use nano

nano /storage/.config/autostart.sh

So for my Syncthing setup the autostart.sh looked like this on OpenElec:

(
 /storage/syncthing-linux-arm-v0.11.8/syncthing;
) &

I also added another line to have the autostart.sh make a text file telling me how much free space was left on the remote drives, and use Syncthing to sync it to my local folder:

(
 sleep 30; df -h | grep /dev/sd > /var/media/[your-Sync-Folder-here]/freespace.txt
) &

The sleep is necessary to let OpenElec mount the drive before putting the text file into it.

Hope it’s useful to someone :slight_smile:

1 Like

Thanks this is a great tip! Until OSMC comes out as alternative for OpenElec, I am stuck with OpenElec so I was looking for a solution like this.

Unfortunately for me, it does not want to start Syncthing, “Permission denied”. I am on OpenElec 5.0.8 and try to use Syncthing for the first time. I login as root via SSH, I do not understand why I get this message.

My autostart.sh:

#!/bin/sh
sleep 2
mkdir /media/esata
mount -O move /media/mydrivelabel /media/esata
(
/storage/syncthing/syncthing;
) &

I have a Cubox-i4 Pro and a eSATA HDD connected to it. All my media is expected by Kodi to be on /media/esata/ so I need those first two commands to make sure my HDD is mapped to that path. But those commands don’t affect yours as this is the output when I run the script:

CuboxTV:/ # /storage/.config/autostart.sh: line 7: /storage/syncthing/syncthing: Permission denied

How can I run Syncthing succesfully?

====== SOLVED:

CuboxTV:~ # cd /storage/syncthing
CuboxTV:~/syncthing # chmod +x syncthing

and a note for others and myself in the future:

nano /storage/.config/syncthing/config.xml

Final steps:

  1. Modify 127.0.0.1 to 0.0.0.0 to be able to access the webUI on other systems.
  2. Go to the webui, Settings and set a username and password with HTTPS checked.
2 Likes

Is /storage/syncthing/syncthing marked as executable?

1 Like

that was the mistake, I updated my post :slight_smile:

2 Likes

Hi there I found this forum while searching for a solution to run btsync on my raspberry i´m stuck afer

nano /etc/apt/sources.list.d/btsync.list past following lines: deb http://debian.yeasoft.net/btsync wheezy main contrib non-free deb-src http://debian.yeasoft.net/btsync wheezy main contrib non-free

while following this tutorial

I really don´t have a clue about how to set up btsync due openelec hasn’t activate apr-get command so any help would be very highly appreciated!

obviously I´m a complete newbie…

Thank you very much for any support and help

regards!

@rubbo this is the forum for Syncthing not BTSync :wink:

1 Like

Holy MOther of God…sorry about that… after googleing I found the very first post and I saw a light of hope…

keep searching

Thanks!

1 Like

Why don’t you switch to Syncthing on your Raspberry?

1 Like

Don’t forget to set a username and password. Please add this to your notes, thx

1 Like