"pid_file" setting not working


azar

Recommended Posts

Hello,

 

My OS is Ubuntu 12.04.3 (i386) and my BTSync config in /etc/btsync/my.conf is as follows (also, I'm using server variant of BTSync, that is, not "btsync-user" one):

//!/usr/lib/btsync/btsync-daemon --config//// DAEMON_UID=MYUSERNAME//{	"device_name": "MY DEVICE",	"storage_path" : "/home/MYUSERNAME/.btsync-MYUSERNAME",	"pid_file" : "/home/MYUSERNAME/.btsync.MYUSERNAME.pid",	"listening_port" : 0,	"check_for_updates" : false,	"use_upnp" : true,	"download_limit" : 0,	"upload_limit" : 0,	"disk_low_priority" : true,	"lan_encrypt_data" : true,	"lan_use_tcp" : false,	"rate_limit_local_peers" : false,	"folder_rescan_interval" : 600,	"webui" :	{		"listen" : "0.0.0.0:8888",		"login" : "admin",		"password" : "MYPASSWORD"	}} 

The issue is -  when I run (without sudo, as I dont want to run it as root):

service btsync start

I get the error:

 

 

start-stop-daemon: unable to open pidfile '/var/run/btsync.MYUSERNAME.pid' for writing (Permission denied)

 

 

Well, sure permission denied, there is no sudo!

 

But how come my "pid_file" setting is ignored?

 

I have found something here:

 

 

 

In any case, the service (/usr/lib/systemd/system/btsync@.service) assumes that the PID file is at ~/.config/btsync/sync.pid. Unless you explicitly set the "pid_file" setting in your config file, the sync.pid file is created in the "storage_path" directory. If you've changed either of those settings, you'll need to update the PIDFile setting in the service accordingly.

 

 

If so, and I need to edit "btsync@.service", where can I find it on my system? These instruction are for Arch, and I also ran (from root location) "sudo find -maxdepth 9999 -name *btsync*" and this did not return "btsync@.service".

 

Any ideas?

Link to comment
Share on other sites

Not really. Look:

 

I created a user user1 and a corresponding configuration file:

 

yeasoft-gate2 /etc/btsync # cat user1.conf//!/usr/sbin/btsync-daemon --config//// DAEMON_UID=user1// DAEMON_GID=user1//{"device_name": "user1@server.domain.lan","listening_port" : 0,"storage_path" : "/home/user1/.btsync","pid_file" : "/home/user1/.btsync/btsync.pid","check_for_updates" : false,"use_upnp" : false,"download_limit" : 0,"upload_limit" : 0,"disk_low_priority" : true,"lan_encrypt_data" : false,"lan_use_tcp" : false,"rate_limit_local_peers" : false,"folder_rescan_interval" : 600,"webui" :{"listen" : "0.0.0.0:61009","login" : "admin","password" : "blablabla"}}

 

... the home directory is still empty...

 

yeasoft-gate2 /etc/btsync # ls -la /home/user1total 20drwxr-xr-x 2 user1 user1 4096 Sep 18 17:31 .drwxr-xr-x 6 root  root  4096 Jul 17 00:04 ..-rw-r--r-- 1 user1 user1  220 Apr  3  2012 .bash_logout-rw-r--r-- 1 user1 user1 3486 Apr  3  2012 .bashrc-rw-r--r-- 1 user1 user1  675 Apr  3  2012 .profile

 

Now let's start the party...

 

yeasoft-gate2 /etc/btsync # sudo service btsync start * Starting P2P file synchronisation daemon(s)... * Autostarting btsync instance 'user1'                                                     [ OK ]

 

Fine. Let's look at the user's home directory...

 

yeasoft-gate2 /etc/btsync # ls -la /home/user1total 24drwxr-xr-x 3 user1 user1 4096 Sep 18 17:32 .drwxr-xr-x 6 root  root  4096 Jul 17 00:04 ..-rw-r--r-- 1 user1 user1  220 Apr  3  2012 .bash_logout-rw-r--r-- 1 user1 user1 3486 Apr  3  2012 .bashrcdrwxr-xr-x 2 user1 user1 4096 Sep 18 17:32 .btsync-rw-r--r-- 1 user1 user1  675 Apr  3  2012 .profileyeasoft-gate2 /etc/btsync # ls -la /home/user1/.btsync/total 288drwxr-xr-x 2 user1 user1   4096 Sep 18 17:32 .drwxr-xr-x 3 user1 user1   4096 Sep 18 17:32 ..-rw-r--r-- 1 user1 user1      5 Sep 18 17:32 btsync.pid-rw-r--r-- 1 user1 user1   2400 Sep 18 17:32 settings.dat-rw-r--r-- 1 user1 user1  74135 Sep 18 17:32 sync.lng-rw-r--r-- 1 user1 user1      0 Sep 18 17:32 sync.log-rw-r--r-- 1 user1 user1 198451 Sep 18 17:32 webui.zip

 

Perfect! Everything OK! And btsync is running as user1. But is there also a .pid file in /var/run?

 

yeasoft-gate2 /etc/btsync # ls -la /var/run/bt*-rw-r--r-- 1 root root 5 Sep 18 17:32 /var/run/btsync.user1.pid

 

 

Oh! Why another PID file? OK - now the answer and also the solution to your problem:

 

The first .pid file (the one in the home directory of the user) is created by btsync itself, and therefore it runs under the credentials of user1 - since in the config file it was stated that btsync should run as user1.

 

The second .pid file (the one under /var/run is created by the daemon script - that should be managed by the daemon subsystem since it is autostarted by init on system startup.

 

So: when you execute 

 

service btsync start
 
under normal user credentials, you are doing something that is not correct, since services (daemons) are always managed by the system. You can't also use the service command to start other services like dhcp or named with user credentials.
 
Start btsync with
 
sudo service btsync start
 
and you will see that everything is working as you like - also the btsync instance running as MYUSERNAME (since you have specified it in the configuration file.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.