2nv2u / gnome-shell-extension-syncthing-indicator

Put an indicator on the panel signalling the Syncthing daemon status using SystemD
https://extensions.gnome.org/extension/1070/syncthing-indicator/
GNU General Public License v3.0
57 stars 9 forks source link

Cannot find Syncthing config #40

Open salim-b opened 2 months ago

salim-b commented 2 months ago

I'm trying to run Syncthing Indicator on the immutable Linux distro Bluefin (which is based on [Universal Blue]() which in turn is based on Fedora Silverblue). Syncthing is installed via brew install syncthing.

I understand that Syncthing Indicator ships its own systemd service unit, so I did not enable the one shipped with Homebrew (would be enabled via brew services start syncthing). Instead, I adapted the one that Syncthing Indicator installed (~/.config/systemd/user/syncthing.service) to

The above env vars are also set in my ~/.bashrc:

export STCONFDIR='/var/home/salim/.config/syncthing'
export STDATADIR='/var/home/salim/.local/state/syncthing'

After running systemctl --user daemon-reload; systemctl --user restart syncthing.service, Syncthing appears to be running fine (systemctl --user status syncthing.service looks good) and the Syncthing web interface is accessible under the default http://127.0.0.1:8384/ address. syncthing --paths on a terminal gives the expected output, i.e. is using the correct config/state directories:

``` Configuration file: /var/home/salim/.config/syncthing/config.xml Device private key & certificate files: /var/home/salim/.config/syncthing/key.pem /var/home/salim/.config/syncthing/cert.pem GUI / API HTTPS private key & certificate files: /var/home/salim/.config/syncthing/https-key.pem /var/home/salim/.config/syncthing/https-cert.pem Database location: /var/home/salim/.local/state/syncthing/index-v0.14.0.db Log file: - GUI override directory: /var/home/salim/.config/syncthing/gui Default sync folder directory: /var/home/salim/Sync ```

But Syncthing Indicator fails to find the Syncthing config. Logs:

137743: Aug 11 19:23:41 salim-laptop gnome-shell[16036]: syncthing-indicator-manager: can't find config file
137744: Aug 11 19:23:41 salim-laptop gnome-shell[16036]: syncthing-indicator-manager: Config not found
137745: Aug 11 19:23:41 salim-laptop gnome-shell[16036]: syncthing-indicator: config-error {
137748: Aug 11 19:23:41 salim-laptop gnome-shell[16036]: error: Syncthing Indicator: Cannot find Syncthing config, syncthing might not be installed, check log for more details
137749: Aug 11 19:23:41 salim-laptop gnome-shell[16036]: syncthing-indicator-manager: can't find config file
137750: Aug 11 19:23:41 salim-laptop gnome-shell[16036]: syncthing-indicator-manager: can't find config file
137751: Aug 11 19:23:41 salim-laptop gnome-shell[16036]: syncthing-indicator-manager: can't find config file

(last line is repeated a few more times)

The following code seems responsible to detect Syncthing's config:

https://github.com/2nv2u/gnome-shell-extension-syncthing-indicator/blob/fe58a1a3ea9a9c278c83b31c22f8bcead16e6e95/src/syncthing.js#L359-L401

I guess the reason why it fails in my case is that the STCONFDIR and STDATADIR env vars are not set during GLib.spawn_sync(null, ['syncthing', '--paths'], null, GLib.SpawnFlags.SEARCH_PATH, null)? If so, how could I fix that?

2nv2u commented 2 weeks ago

It should try to read the config from syncthing --paths which is a syncthing command returning paths, if that does not return anything it should revert back to GLib.get_user_config_dir() + '/syncthing/config.xml' which is the default path. It looks like both this things do not return the right file or it fails in executing the syncthing paths command.

Can you test that? I'll then look into making this code more robust...

salim-b commented 2 weeks ago

It should try to read the config from syncthing --paths which is a syncthing command returning paths

Yes, I know that. As I wrote above, I've set STCONFDIR and STDATADIR explicitly in Syncthing's systemd service unit and in my ~/.bashrc and syncthing --paths on a terminal gives me the expected output..

if that does not return anything it should revert back to GLib.get_user_config_dir() + '/syncthing/config.xml' which is the default path.

This is not quite correct anymore since

Changed in version 1.27.0: The default location of the configuration and database directory on Unix-like systems was changed to $XDG_STATE_HOME/syncthing or $HOME/.local/state/syncthing. Previously the default config location was $XDG_CONFIG_HOME/syncthing or $HOME/.config/syncthing. The database directory was previously $HOME/.config/syncthing or, if the environment variable was set, $XDG_DATA_HOME/syncthing. Existing installations may still use these directories instead of the newer defaults.

So what happens I guess is that during GLib.spawn_sync(null, ['syncthing', '--paths'], ...) STCONFDIR and STDATADIR are not set (i.e. ~/.bashrc is ignored) and hence the config dir this syncthing --paths invocation returns defaults to $HOME/.local/state/syncthing – but my Syncthing config is actually located at $HOME/.config/syncthing/config.xml.

A more robust approach would be to call the REST API of the running Syncthing instance via GET /rest/system/paths, I guess.