Ubuntu 14.04 LTS server syncthing problem installation and autostart

Hey,

I am fairly new to syncthing but it is great. However I would need your help with something.

My setup: I have 2 Windows 10 computers on which I have successfully installed syncthing and auto start them using the task scheduler. Both are running the newest release of syncthing and are syncing.

Now I wanted to setup an old laptop as sort of a man in the middle if one or the other Windows 10 computer is not connected and running.

The laptop is running Ubuntu 14.04 LTS server with no GUI and static IP address.

I have followed this tutorial to install syncthing:

Except for the IP tables part. I have opened port 8080 in ufw and have added the other ports via a ufw configuration file for syncthing:

It is located in: /etc/ufw/applications.d

With this content:

[Syncthing]

title=Syncthing

description=Open Source Continuous File Synchronization

ports=22000/tcp|21027/udp

Afterwards I added it with sudo ufw allow syncthing and rules were successfully written.

My upstart file /home/ben/.config/upstart/syncthing.conf looks like this: it is a modified version of the one included in the tutorial. I changed the folder locations and the upstart events. Due to only being able to post one link I removed the links in the script but you can see the original version in the referenced tutorial.

_> Upstart Configuration File for Ubuntu 14.10 - to run syncthing
_> #
_> #  Created 27 Dec 2014 - initial file written based on version from 
_> #  Syncthing forums here: 
_> #  link removed please see referenced tutorial for original
_> #
_> #
_> # BEFORE USE: change:
_> #
_> #   1) the 'env SYNCTHING_EXE=' line below so it has the correct path 
_> #      to wherever you have installed the syncthing executable on your
_> #      computer - maybe '$HOME/bin'?
_> #      Enter the full path, as the use of $HOME wont work (I believe?) 
_> #      as Upstart does not inherit your normal environment variables.
_> #
_> #   2) the 'env SYNCTHING_CONF=' so the path shown to the 'syncthing' 
_> #      configuration files is right.  The default location is: 
_> #             $HOME/.config/syncthing
_> #      In the line below, the text "/home/simon/.config/syncthing" needs
_> #      to match your own home directory location. So on Ubuntu - the 
_> #      directory path needs to be changed, replacing the word  'simon'
_> #      with your own username. The use of $HOME wont work (I believe?)
_> #      as Upstart does not inherit your normal environment variables.
_> #
_> # INSTALLATION:
_> #  To install and use - copy (or symlink) this file (once updated) to
_> #  this path on you computer: 
_> #
_> #         $HOME/.config/upstart/syncthing.conf
_> #
_> #  If you want to find that folder in the graphical Ubuntu 'Files'
_> #  application (ie Nautilus), you will need to first press the keys
_> #  'Ctrl+h' on you keyboard to see hidden items. 
_> #  The '.config' folder should then be visible, and enable you to 
_> #  navigate into it. Press the keys 'Ctrl+h' on you keyboard to re-hide
_> #  the hidden items when done. Other wise just copy the file in a Terminal
_> #  window with the 'cp' command
_> #
_> # NB: You will need to login out of your desktop and back in to start 
_> #     syncthing running!
_> #
_> # LOGGING INFO:
_> #  Any output will be logged to: $HOME/.cache/upstart/syncthing.log 
_> #  (or syncthing.log.1.gz) To view the last 50 log entries in the file 
_> #  from a terminal window use the command:
_> #
_> #       tail -50 $HOME/.cache/upstart/syncthing.log
_> #
_> #  or if the system has gziped the log file, you can use the equivalent
_> #  command:
_> #
_> #        zcat $HOME/.cache/upstart/syncthing.log.1.gz | tail -50
_> #
_> # NOTES:
_> #  syncthing startup options used:
_> #
_> #   -no-browser : stops a browser window being opened if syncthing starts
_> #   up or restarts
_> #   -home="$SYNCTHING_CONF" : default syncthing configuration files location
_> #
_> # You can also add below the following syncthing environment variable options
_> # if required:
_> #
_> #   env STNORESTART=yes 
_> #          : if syncthing crashes or tries to restart, it will just exit 
_> #          instead
_> #   env STTRACE=beacon,net
_> #          : will enable debug output for 'beacon' & 'net'. See the Syncthing
_> #          forum post here for more info: 
_> #  link removed please see referenced tutorial for original
_> #
_> # You can run syncthing from a terminal window to see a full list of the 
_> # command line options that are available. The command to use is:
_> #
_> #    syncthing --help
_> #
_> #
_> # CHANGE BELOW TO MATCH YOUR REQUIREMENTS:
_> #----------------------------------------------------------------------#
_> env SYNCTHING_EXE="/usr/bin/syncthing"
_> env SYNCTHING_CONF="/home/ben/.config/syncthing"
_> env STNORESTART=yes 
_> #----------------------------------------------------------------------#
_> # set the name of the application
_> description "Syncthing"
_> # when Upstart should start syncthing - so when you login to your desktop
_> #start on desktop-start
_> start on (local-filesystems and net-device-up IFACE!=lo)
_> # when Upstart should stop syncthing - so when you logout to your desktop
_> #stop on desktop-end
_> stop on runlevel [!2345]
_> setuid "ben"
_> setgid "ben"
_> # the syncthing command Upstart is to execute when it is started up
_> exec $SYNCTHING_EXE -no-browser -home="$SYNCTHING_CONF"

_> # If Upstart detects syncthing has failed - it should restart it
_> respawn

I could start syncthing succesfully via command: syncthing

But it will not autostart after I reboot the server.

There is also no file in /home/ben/autostart

No after messing with it I cannot even get it to run manually anymore :-(.

Can anyone help? I just want syncthing to run on my Ubuntu server as a service and autostart after I reboot the server with sudo reboot command.

Thank you!

Ubuntugeek

Ok, I repaired my installation of syncthing so that I can manually start it using command syncthing.

Still no working autostart

On the phone at the moment but that guide seems out of date. What PPA are you using? Please use apt.syncthing.net it is maintained by the development team.

1 Like

Upstart files should be in the /etc/init/ directory. Your home folder will not be checked on boot.

I don’t use upstart a lot but why not just start on startup?
I would export the home variable… it is just good practice.

Hello, Thanks for your answer. PPA that I am using is the one from the tutorial: ppa:ytvwld/syncthing.

How do you make your paths that pretty?

So are you saying I need to put the syncthing.conf file in /etc/init ?

What do you mean by export the home variable or why not use start on startup?

A script like this:

start on startup task exec /path/to/command

Why is upstart not checked @boot?

It is, upstart scripts are kept in /etc/init/ only user scripts are kept in the home folder. They are triggered on login etc.[quote=“Ubuntugeek, post:5, topic:7867”] What do you mean by export the home variable or why not use start on startup? [/quote]

I would put export HOME=... into the upstart script. It is common for Programs and scripts on Linux to expect it to exist. You have used the syncthing specific option instead which should work. Google it and have a look.

Your start on line is fine. I was just asking a question.

Remove that one and add the apt.syncthing.net one in stead. Instructions for adding it can be found at http://apt.syncthing.net If you need help removing a PPA a quick Google should do it.

In the forum you can wrap commands etc. In back ticks “`”. The key before 1 on American keyboards.

Hello,

Sorry for the delayed response. I have done a clean install of my server yesterday. There is currently no firewall active and there is only openssh and syncthing installed.

I have put the syncthing.conf in the /etc/init and rebooted the server using ssh connection, didn’t start syncthing.

Then I made a file called sync.config with

start on startup task exec /usr/bin/syncthing

And put that into /etc/init.

Didn’t work either…

The binary is in that location though I double checked it is it because of the ssh reboot?

Haven’t figured out that part yes.

Didn’t mean to be offensive in any way. Either working way for an automatic start would be greatly appreciated.

Thanks for your help!

You didn’t offend me, I just didn’t want you to worry about it for the time being. Both that and exporting home shouldn’t affect the script working.

How are you checking if it is running?
Do you still have the -home flag set?
Check the upstart config with init-checkconf
Have you run sudo service syncthing start?

Ok, sudo Service syncthing Start returns unknown service.

The [quote=“kluppy, post:9, topic:7867”] Check the upstart config with init-checkconf [/quote]

Asks for a config name and when I say syncthing it says no such config exists.

Do not know what exactly you referring to with the home flag part

Tell the command the path to the config file e.g. init-checkconf /path/to/file

Path to the file in /etc/init ?

Yes, I think the file is named wrong if the service cannot be found. it is based on the name of the config file.

syncthing.conf would be triggered with sudo service syncthing start

It has a syntax error. Unknown stanza, which I fixed. Now init-checkconf says syntax fine and sudo service syncthing start returns that the process is running but when I try to access the gui via browser it will not find anything did I shut that off? How to tell if it is really running and how to configure it without browser being accessible. I use the static ip of the server and the port that I have specified in the config.xml in the home folder.

When you start a service via upstart the output will be logged under /var/log/upstart/service_name.log Have a look at what is in the log.

Run ps -A | grep sync. This will list all of the running processes with sync in their title. If nothing is printed Syncthing is failing to start for some reason.

I would edit the the config.xml directly or search the forum for accessing remote Syncthing instances. I think it has been written about a few times.

It says Fatal error no home directory found set $home$[quote=“kluppy, post:16, topic:7867”] Dear users of Syncthing,

By default, the web GUI only listens for connections from localhost (127.0.0.1 or ::1 for ipv6).

If you decide to change this to make it listen to the whole world (for example, 0.0.0.0), then make sure you set up a username, password and HTTPS.

Otherwise, anybody can connect to your server [/quote]

But only from within mynetwork, right? It is still behind the router with no ports forwarded or what would you suggest that I use?

Thank you!

That depends on your network setup but, in general, I think it’s unsafe. There are countless situations where your network might not be as private or trustworthy as you’d like. Many IPv6 implementations will expose your machine to the world by default. And what about your printer, or your friend’s obsolete Android smartphone? Do you update your router regularly in response to security disclosures? Et cetera.

I understand so what to change it to? To the servers static ip?

So Syncthing is failing to start because it can’t find where the configuration is supposed to be kept.

What is your exec line? does it still have -home=? Does the directory this option points to exist?

If you have checked all of this and still can’t get it I will upload a version that should work.