# Keeping Syncthing Running: Systemd & regular /etc/init.d

**URL:** https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402
**Category:** Howto
**Created:** [June 17, 2014, 11:58am UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402 "2014-06-17T11:58:55Z")
**Posts on this page:** 13
**Page:** 2

<div class="post-metadata">

### Author: ![thfr](https://forum.syncthing.net/user_avatar/forum.syncthing.net/thfr/32/521_2.png) [@thfr](https://forum.syncthing.net/u/thfr)
#### Post date: [October 20, 2014, 8:56am UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/21 "2014-10-20T08:56:11Z")

</div>

When `STNORESTART=yes` is set, Syncthing/Pulse returns 3 as an exit code and Systemd will not restart it unless you add `SuccessExitStatus=3` to the service file. A restart from the web gui would not work otherwise.

```
[Unit]
Description=Syncthing service for %i
After=network.target

[Service]
User=%i
Environment=STNORESTART=yes
ExecStart=/usr/bin/syncthing
Restart=on-success
SuccessExitStatus=3 

[Install]
WantedBy=multi-user.target
```

---

<div class="post-metadata">

### Author: ![paradon](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/p/b9bd4f/32.png) [@paradon](https://forum.syncthing.net/u/paradon)
#### Post date: [October 22, 2014, 8:21pm UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/22 "2014-10-22T20:21:55Z")

</div>

I am running OpenSuse 13.1 and I have no experience in systemd services and would like to explain the problems I had when I tried this guide.

Tried multiple different options including copying syncthing.service to systemd/user folder and so on.

$systemctl start syncthing Failed to issue method call

$systemctl --user start syncthing Failed to get D-Bus connection: Did not receive a reply

The solutions to my problem was provided [here](http://sudhirkhanger.com/2014/09/09/install-syncthing-on-fedora/) in proper order:

1. Copy the systemd service from first post and save as syncthing@.service in folder: /etc/systemd/system/multi-user.target.wants/
2. $systemctl enable syncthing@$USER.service
3. $systemctl start syncthing@$USER.service

Now everything seems to be working fine.

---

<div class="post-metadata">

### Author: ![hobarrera](https://forum.syncthing.net/user_avatar/forum.syncthing.net/hobarrera/32/519_2.png) [@hobarrera](https://forum.syncthing.net/u/hobarrera)
#### Post date: [October 24, 2014, 12:22pm UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/23 "2014-10-24T12:22:36Z")

</div>

> [@bsidhom](#):
>
> What are the advantages and disadvantages of running via systemd/upstart versus a user-specific @reboot crontab daemon entry?

Stopping/restarting would be a PITA. Especially the latter.

> [@dereke](#):
>
> When using systemd I found that I needed to create the config file in the users scripts directory. In fedora 20 that was
> 
> /etc/systemd/users/syncthing.service

You’re supposed to run it as `sudo systemctl start syncthing@USERNAME`, not `systemctl --user`.

> [@thfr](#):
>
> I am using syncthing as systemd user service via systemctl --user in arch linux.

What I just said above applies. Also, the ArchLinux package actually displays a message post-installation telling you exactly this.

---

<div class="post-metadata">

### Author: ![thfr](https://forum.syncthing.net/user_avatar/forum.syncthing.net/thfr/32/521_2.png) [@thfr](https://forum.syncthing.net/u/thfr)
#### Post date: [October 29, 2014, 3:07pm UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/24 "2014-10-29T15:07:16Z")

</div>

> [@hobarrera](#):
>
> You’re supposed to run it as `sudo systemctl start syncthing@USERNAME`, not `systemctl --user`.

I did not miss the install message. Do you know why this is? I would like it better, when this service is controlled by the user itself, that is why I tried to get it working with `systemctl --user`.

---

<div class="post-metadata">

### Author: ![hobarrera](https://forum.syncthing.net/user_avatar/forum.syncthing.net/hobarrera/32/519_2.png) [@hobarrera](https://forum.syncthing.net/u/hobarrera)
#### Post date: [October 29, 2014, 4:50pm UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/25 "2014-10-29T16:50:55Z")

</div>

> [@thfr](#):
>
> I did not miss the install message. Do you know why this is? I would like it better, when this service is controlled by the user itself, that is why I tried to get it working with systemctl --user.

Is there any reason why you can’t just `sudo systemctl`? The service runs as the user anyway. And it can restart itself once it’s started. (or you can kill it and have systemd restart it for you).

---

<div class="post-metadata">

### Author: ![thfr](https://forum.syncthing.net/user_avatar/forum.syncthing.net/thfr/32/521_2.png) [@thfr](https://forum.syncthing.net/u/thfr)
#### Post date: [October 30, 2014, 7:26am UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/26 "2014-10-30T07:26:15Z")

</div>

Like I said, as a user space process it should be controlled by the user. The user can not stop or start any services of this type, because the service was set by the super user. Correct if I am wrong but I think that the service is started at system start and therefore can affect the overall performance depending on the number of users using syncthing, repositories and so on. The user service manager (`systemctl --user`) is started on the first log in of the according user and its logs can only be viewed by the according user (privacy). I know for a single user system there is no difference but for multi user systems it makes sense to use the user service manager and I am always glad to keep my activities in user space 🙂

---

<div class="post-metadata">

### Author: ![hobarrera](https://forum.syncthing.net/user_avatar/forum.syncthing.net/hobarrera/32/519_2.png) [@hobarrera](https://forum.syncthing.net/u/hobarrera)
#### Post date: [October 30, 2014, 7:52am UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/27 "2014-10-30T07:52:55Z")

</div>

> [@thfr](#):
>
> I know for a single user system there is no difference but for multi user systems it makes sense to use the user service manager and I am always glad to keep my activities in user space

As I said before, the above script runs the service as the configured your (eg: your user, not root), even if it’s started by root (systemd will change user before starting the process). (I’m assuming that’s what you refer to with “user space”, since syncthing can’t run outside user space).

I do agree on the multi-user point; syncthing _may_ degrade performance on shared hosts or have other undesired effects. Just also keep in mind that by running with `systemd --user` syncthing will not sync files until you log in on more than one host simultaneously.

---

<div class="post-metadata">

### Author: ![dmacvicar](https://forum.syncthing.net/user_avatar/forum.syncthing.net/dmacvicar/32/5290_2.png) [@dmacvicar](https://forum.syncthing.net/u/dmacvicar)
#### Post date: [October 30, 2014, 11:09pm UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/28 "2014-10-30T23:09:09Z")

</div>

If you use a package, then the systemd script comes ready to use (for openSUSE)

See [https://pulse-forum.ind.ie/t/opensuse-package-for-syncthing/189/26](https://pulse-forum.ind.ie/t/opensuse-package-for-syncthing/189/26)

---

<div class="post-metadata">

### Author: ![tomek](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/t/3ab097/32.png) [@tomek](https://forum.syncthing.net/u/tomek)
#### Post date: [February 10, 2015, 10:50am UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/29 "2015-02-10T10:50:48Z")

</div>

I would like to tweak the init.d script for debian, in order to keep logs in a file. How can I do this ?

---

<div class="post-metadata">

### Author: ![urza](https://forum.syncthing.net/user_avatar/forum.syncthing.net/urza/32/997_2.png) [@urza](https://forum.syncthing.net/u/urza)
#### Post date: [March 22, 2015, 12:26pm UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/30 "2015-03-22T12:26:58Z")

</div>

I have debian, [used this init.d script](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/27) mixed with [this installation guide](https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-syncthing-to-synchronize-directories-on-ubuntu-14-04). Result is that I have syncthing running as a dameon/service by user syncthing. It was working ok for few days, but now I cannot connect to web gui… when I go to my IP:port there is no response, it jsut loads forever.

The syncthing pseems to be running because:

```
syncthing@cedrus:$ sudo service syncthing status
syncthing for USER syncthing: running (pid 2268024987)

```

It looks like for whatever reason the `/etc/init/syncthing.conf` is missing… there is no such file…

Any ideas what went wrong and how to correct it?

---

<div class="post-metadata">

### Author: ![urza](https://forum.syncthing.net/user_avatar/forum.syncthing.net/urza/32/997_2.png) [@urza](https://forum.syncthing.net/u/urza)
#### Post date: [March 22, 2015, 12:54pm UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/31 "2015-03-22T12:54:14Z")

</div>

To reply to myself.

I find out that the syncthing confing is actually in home directory `./config/syncthing/config.xml`

there in the config in the gui section was some “\> api key” which i dont remember setting, so I removed it

Then for whatever reason the `service syncthing status` was returning 6 processes, so I killed them all, and restarted as service syncthing start

and it works again…

wonder why this all happened…

I am evaluating syncthing as a replacement for my dropbox, but so far it is too much geeky, expecially the server part (syncthing running as daemon on my little debian box)…

---

<div class="post-metadata">

### Author: ![prodigy7](https://forum.syncthing.net/letter_avatar_proxy/v4/letter/p/7cd45c/32.png) [@prodigy7](https://forum.syncthing.net/u/prodigy7)
#### Post date: [March 29, 2015, 8:49am UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/32 "2015-03-29T08:49:37Z")

</div>

A light modified version of the debian init.d script can be found here: [http://download.prodigy7.de/files/programs/any/syncthing/syncthing](http://download.prodigy7.de/files/programs/any/syncthing/syncthing) Output from stdout are redirected to logfile in /var/log. Please add init script to package.

---

<div class="post-metadata">

### Author: ![AudriusButkevicius](https://forum.syncthing.net/user_avatar/forum.syncthing.net/audriusbutkevicius/32/277_2.png) [@AudriusButkevicius](https://forum.syncthing.net/u/AudriusButkevicius)
#### Post date: [March 29, 2015, 11:45am UTC](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402/33 "2015-03-29T11:45:11Z")

</div>

Please make a pull request.

[Previous page](https://forum.syncthing.net/t/keeping-syncthing-running-systemd-regular-etc-init-d/402.md?page=1)
