Running the nextcloud client under systemd

Since my nextcloud sync client kept crashing due to too many open files, I wanted to have something auto-restart it. Also, I recently stumbled across the awesome fact that nowadays, every Linux Desktop session also includes its very own systemd user instance, so I put the nextcloud client under its supervision. Here’s how.

First of all, run this command to have systemctl create a new service:

systemctl --user edit --force --full nextcloud.service

Paste in this service definition:

[Unit]
Description=nextcloud
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
ExecStart=/usr/bin/nextcloud
Restart=on-failure
RestartSec=5s
LimitNOFILE=65535:65535

[Install]
WantedBy=multi-user.target

Enable and start the service:

systemctl --user enable nextcloud.service
systemctl --user start nextcloud.service

Check status using:

systemctl --user status nextcloud.service

Your Nextcloud client should just start up and appear in your Desktop tray as usual, but now it’s running under the supervision of systemd \o/