Run ResilioSync (Btsync) as normal user under Ubuntu

Today I re-installed my home Intel NUC to Ubuntu 16.04. And I have to re-install and re-setup my ResilioSync service. I have to change the default deamon user to my login user, so the daemon process can access my mounted external hard driver. I guess some people will have the same problem, so in this article I will share the step to do it.

(If you have not installed resilio sync in your ubuntu yet, here is the official steps to do it)

The problem

By default the resiliosync service is running under rslsync user and group, but my external NTFS driver is mounted as my login user, which makes the rslsync service failed to create files or folders in my mounted NTFS directory.

I checked the background daemon process, and found it was running under a separate user rslsync:

that’s why it can not access other folders. To solve this problem, one work around is to use chown to change the user and group of the folder to rslsync, but it is not good enough. Let’s try to do the right thing, which is run the rslsync daemon process under the same user as your login user.

Run daemon under login user

As you may know, the latest Ubuntu finally start to use systemd and the default service manager. Here our resilio service is also running under the control of systemd. We can see the unit file by this command:

As we can see, it explicitly specified the user and group to rslsync, and even created directory and set the owner to this default rslsync user.

We just need to change the User and Group options value to our username and group name. But before doing that, I found something better we can do. When I check the default config.json file, I found there is an additional script in that same folder:

see the file, it’s executable, let’s see what’s inside the script:

its logic is very clear, this script helps us create a resilio config folder and config file for a normal user, which means if I run this script by my login user, I will have every config file under my home folder. Let’s do it and see what we will get:

It’s good. It creates a config file for our login user(as you can see, my login user name is laputa) and fill in necessary values in the config file. Next step, we just need to change the systemd service file to make it work.

Fortunately, systemd provides a convenient way to override the service unit file and provide our own configurations. It’s called a drop-in snippet:

this command will create a file named /etc/systemd/system/resilio-sync.service.d/override.conf , and as the name says, it will override the original unit file in /lib/systemd/system/resilio-sync.service, a few things to mention:

  • User & Group: just set to our normal login user name
  • PIDFile: changed to the file in our new user config.json file, systemd will use this file to get the main PID
  • ExecStartPre: set to empty so we can clear the settings in original unit file, because we are using our own home directory, we don’t need to create and set owners
  • ExecStart: first set to empty to clear the settings in original unit file, this is same as above because systemd only allows one ExecStart option. Then we set the similar start command but specify to use our new user config file

After we save the file, we can see systemd pickup the override file:

Next we can reload the systemd config, and restart the resilio sync service:

As we see, now resilio service is running under my login user, and using my new user config file. It will happily create any files and folders in my external disk.

Software Engineer, Linux lover

Software Engineer, Linux lover