Can't make syncthing-inotify properly autostart at boot

Ehm… That sounds nice but I don’t understand what it means :smiley: Any hints on how to solve the situation? Thanks

Sadly I am not a systemd expert. According to what guide did you set it all up?

Syncthing is already “bundled” in DietPi. Syncthing-inotify isn’t, so I just downloaded the binary from github. But it only works when run manually. I’m using a work around (set it to run at boot in the crontab) but it’s not the optimal solution, of course… :frowning:

Where did you get systemd filea for inotify?

Also from github, in the etc folder of the syncthing-inotify project.

You should start syncthing-inotify (and syncthing) as a particular user: systemctl enable/start/status syncthing-notify@YOURUSER.service.

Should be the solution. Or bind it to a login session using a user instance:

systemctl --user start ...

Here is some old thread about this user instance thing:

Thanks for the suggestion that I am sure would solve the issue. The problem is that syncthing gets automatically installed and run by user ‘root’ in DietPi, and I have no idea how to change this.

The instructions are for the inotify systemd files oppose to syncthing.

Show me the systemd files from your system; I will explain it.

This should be filed as a bug on DietPi, whatever that is.

Are you sure that it’s set to run as root by default? Or did it just install the systemd files, and you set it to start yourself?

DietPi is a lightweight distribution for development boards like Raspberry Pi, Banana Pi, Odroid and the likes. It has a selection of optimized software that can be installed easily and quickly, and syncthing is one of them. I won’t have access to the board until tomorrow, but as soon as I can I will post the systemd syncthing.service and the two from the syncthing-inotify github, in order to understand what’s wrong. I realize that it would be better if syncthing were run as a normal user, but I guess that even root is a user, and therefore everything should run correctly even if started as root, shouldn’t it?

I managed to get my hands on the “.service” files:

/etc/systemd/system/syncthing.service:

[Unit]
Description=Syncthing
 
[Service]
Type=oneshot
ExecStart=/bin/bash -c '/usr/bin/syncthing > /var/log/syncthing.log &'
ExecStop=/usr/bin/killall -w syncthing
RemainAfterExit=yes
User=root
 
[Install]
WantedBy=multi-user.target

For syncthing-inotify:

/etc/systemd/system/syncthing-inotify.@service:

[Unit]
Description=Syncthing Inotify File Watcher for %I
Documentation=https://github.com/syncthing/syncthing-inotify/blob/master/README.md
After=network.target syncthing@.service
Requires=syncthing@.service

[Service]
User=%i
ExecStart=/usr/bin/syncthing-inotify -logflags=0
SuccessExitStatus=2
RestartForceExitStatus=3
Restart=on-failure
ProtectSystem=full
ProtectHome=read-only

[Install]
WantedBy=multi-user.target

And etc/systemd/user/syncthing-inotify.service:

[Unit]
Description=Syncthing Inotify File Watcher
Documentation=https://github.com/syncthing/syncthing-inotify/blob/master/README.md
After=syncthing.service
Requires=syncthing.service

[Service]
ExecStart=/usr/bin/syncthing-inotify -logflags=0
SuccessExitStatus=2
RestartForceExitStatus=3
Restart=on-failure
ProtectSystem=full
ProtectHome=read-only

[Install]
WantedBy=default.target

Any help sincerely appreciated. Thank you for your time and patience.

1 Like

Right, I think you need to start syncthing-inotify with systemctl enable/start/status syncthing-inotify@root.service, to tell it to run as root.

1 Like

This file is plain wrong:

  • It starts syncthing is root; there is no possibility to overwrite it.
  • It uses some bash Foo in order to create a logfile
  • The type is oneshot (i guess because of the bash foo?)

I would recommend that you replace it with the service file provided by upstream. Then you can just use the instructions from us to run it.

2 Likes

Ok, thanks a lot for your insight. I’m not sure why syncthing is run that WAY. Could it be because DietPi keeps logging in the RAM (to avoid the SD card to be written too frequently)?

Anyway:

Running systemctl enable/start/status syncthing-inotify@root.service does not work. It starts but it doesn’t detect any file changes.

Tomorrow I will try changing the service for syncthing to the one provided by upstream, and see if it works. Otherwise I guess I’ll have to ask the DietPi maintainer to fix this.

I’ll report back after the necessary testing. Thanks a lot for your help so far.

As I said there is no templating in this service. So @foo does nothing in your case.

Sorry I’m a muppet.

LOL, it’s OK. I really appreciate every effort to help.

1 Like

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