Ubuntu 14.04 LTS server syncthing problem installation and autostart

This is my execution line:

exec $SYNCTHING_EXE -no-browser -home="$SYNCTHING_CONF"

With

env SYNCTHING_CONF="/home/ben/.config/syncthing"

Being set before.

The Error seems to suggest the /home/ben/.config/syncthing doesn’t exist.

Try:

# CHANGE BELOW TO MATCH YOUR REQUIREMENTS:
#----------------------------------------------------------------------#
env SYNCTHING_USER="ben"
env SYNCTHING_EXE="/usr/bin/syncthing"
#----------------------------------------------------------------------#
# set the name of the application
description "Syncthing"
# start once the filesystems are mounted and an interface other than loopback is up
start on (local-filesystems and net-device-up IFACE!=lo)
# when Upstart should stop Syncthing
stop on runlevel [!2345]
setuid ben
setgid ben
script
    HOME=$(getent passwd "$SYNCTHING_USER" | cut -d: -f6)
    export HOME
    # the command Upstart is to execute
    exec $SYNCTHING_EXE -no-browser
end script
# If Upstart detects Syncthing has failed it will restart it
respawn

Edit: This exports the home variable. I use this when running things as a real user because a lot of user apps expect it. Unfortunately I am not an upstart guru so I don’t know how to set the user in one place. You can’t seem to use an environment variable with setuid and setgid so it has to be set in at least 3 places.

Haven’t tested this so please let me know if I made a typo.

This works perfectly, now if I would only really understand how I could have figured that out myself. I know you tried to point out the -home export but I just never really understood that part…still so much to learn.

I also changed the listening IP in the config.xml to my servers static ip : port. I hope that addresses your security concerns with the global listening 0.0.0.0:port.

Thank you a lot!

Last question what settings should I apply for good security and only local network syncing?

The default settings have good security.

I’m not sure about restricting to the local network — I’ll leave that question for someone else to answer.

Disable global discovery. If you have assigned the server a static address use that address on the other devices instead of “dynamic”.

Disable Relays, they aren’t required if you only want to sync on the LAN.

So the original approach used the syncthing flag that is made for this purpose. The error you were receiving indicates the directory didn’t exist which is something Syncthing requires when using this flag.

By default Syncthing uses the HOME variable to find the user’s home directory and creates the default configuration if it doesn’t exist. Since the user isn’t logged in the HOME variable isn’t set so my version looks up the user’s details and trims the sting to just have the location of the home directory. Then stores the variable as HOME and exports it so the Syncthing process can access it.

This will work for apps that don’t give you the option to pass a home as well.

P.S.

Sorry for the multiple posts, on the phone and I really struggle with the forum sometimes.

Ok, done that.

I see. That makes sense, so basically you Look up the information based on the user.

And no problem for the multiple posts with the phone. I am posting on the phone, too. I know how hard it is. Can’t tell you how many times it took for some of my answers :slight_smile:.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.