Debian And Ubuntu Server Unofficial Packages For Bittorrent Sync


Recommended Posts

Hi! Can you see my problem?

Selecting previously deselected package btsync.

(Reading database ... 155824 files and directories currently installed.)

Unpacking btsync (from .../btsync_1.1.48-1~squeeze_amd64.deb) ...

Processing triggers for hicolor-icon-theme ...

Setting up btsync (1.1.48-1~squeeze) ...

Starting P2P file synchronisation daemon(s)...Autostarting btsync instance 'debconf-default':invoke-rc.d: initscript btsync, action "start" failed.

dpkg: error processing btsync (--configure):

subprocess installed post-installation script returned error exit status 1

configured to not write apport reports

Errors were encountered while processing:

btsync

E: Sub-process /usr/bin/dpkg returned an error code (1)

-----------------------------------------------------------------------------

# /etc/init.d/btsync start

Starting P2P file synchronisation daemon(s)...Autostarting btsync instance 'debconf-default':.

# ps -ef | grep btsync

root 28017 20989 0 16:14 pts/3 00:00:00 grep btsync

-----------------------------------------------------------------------------

//!/usr/lib/btsync/btsync-daemon --config

//

// Default instance automatically created by debconf

//

// DO NOT EDIT THIS FILE MANUALLY

//

// use dpkg-reconfigure btsync to modify the

// configuration

//

//

{

"device_name": "torrentsync",

"storage_path" : "/var/lib/btsync",

"listening_port" : 012000,

"check_for_updates" : false,

"use_upnp" : false,

"download_limit" : 0,

"upload_limit" : 0,

"disk_low_priority" : true,

"lan_encrypt_data" : true,

"lan_use_tcp" : true,

"rate_limit_local_peers" : false,

"folder_rescan_interval" : 600,

"webui" :

{

"listen" : "0.0.0.0:8888",

"login" : "afdobrotv",

"password" : "*****"

}

}

-------------------------------------------------------------------------------

/usr/lib/btsync/btsync-daemon --config

Specify config file name.

BitTorrent Sync 1.1.48

/usr/lib/btsync/btsync-daemon --config /etc/btsync/debconf-default.conf

Error while parsing config file: Unexpected end of config file (are you missing '}') ?

------------------------------------------------------------------------------------------------------

# dpkg-reconfigure btsync

/usr/sbin/dpkg-reconfigure: btsync is broken or not fully installed

------------------------------------------------------------------------------------------------------

~# lsb_release -a

No LSB modules are available.

Distributor ID: Debian

Description: Debian GNU/Linux 6.0.7 (squeeze)

Release: 6.0.7

Codename: squeeze

# uname -a

Linux 2.6.32-5-amd64 #1 SMP Mon Feb 25 00:26:11 UTC 2013 x86_64 GNU/Linux

Link to comment
Share on other sites

OK - Interesting situation. btsync is not able to start because there is an error in your config file. The ugly thing, is that the config file is created automatically - this means that there is still the possibility in debconf to enter parameters that create erroneous config files. Unfortunately also dpkg-reconfigure does not work...

Let's try to find a solution:

From what I see, specifying the port number with leading zeroes is something that is basically correct, but btsync does not like it (I verified it). Do the following:

  1. Edit /etc/btsync/debconf-default.conf and remove the leading zero from the port number
  2. Execute sudo apt-get -f install
  3. Now the installation should finish
  4. Run sudo dpkg-reconfigure btsync
  5. When asked for the port number, specify a valid port number without the leading zero in order to make sure, that the erroneous data is not written at the next update

I will try to improve the user input check in order to avoid things like this....

Link to comment
Share on other sites

When I ran this command on my RPI:

sudo echo deb http://debian.yeasoft.net/btsync wheezy main contrib non-free >> /etc/apt/sources.list.d/btsync.list

...I received this error message:

bash: /etc/apt/sources.list.d/btsync.list: Permission denied

However, I solved it by changing the command to

sudo sh -c 'echo deb http://debian.yeasoft.net/btsync wheezy main contrib non-free >> /etc/apt/sources.list.d/btsync.list'

Just to let you know.

Someone may have already mentioned this, I haven't read the whole thread.

Link to comment
Share on other sites

Hi,

I've been trying to start btsync as a non-root user. However, I kept getting the "unable to open pidfile '/var/run/btsync.gav.pid' for writing (Permission denied)". Since my user does not have permission to write there this makes sense.

So I changed the "storage_path" variable in the config file which should (I belive) fix the issue. However, this did not work and after looking at the /etc/init.d/btsync it seems the path for the pid (/var/run) is hard-coded into the "start_btsync" method and elsewhere (e.g. "test_running").

Is there a way around this, or is this a current limitation of the script? I'm going to change the script manually, but would prefer a way that will not break on future updates.

Thanks,

Gavin

Link to comment
Share on other sites

Possibly disregard the above, seems changing the script didn't make things work either, although I could get it to create the pid file in the correct place (but then btsync still wouldn't launch). Anyway, for now I have gone back to letting it just be root, which while sub-optimal, at least works.

Link to comment
Share on other sites

....

Is there a way around this, or is this a current limitation of the script? I'm going to change the script manually, but would prefer a way that will not break on future updates.

Hi Gavin,

this is an interesting behaviour. Unfortunately I'm currently on the road and I cannot reproduce your problem. I hope that I can tell you more this nights, when I have access to my servers and computers....

In the meantime you may give me some more information: which operating system are you using, which version and which architecture?

Link to comment
Share on other sites

Hi tuxpoldo,

It seems it was an error on my side (an instance of btsync didn't get killed somehow when I removed and reinstalled from synaptic). Killing this instance and stopping and starting the service fixed the issue.

Sorry for wasting your time, and thanks for the quick response.

Gavin

Link to comment
Share on other sites

Hi again,

So unfortunately there is still an issue. But I'll start again.

System: Ubuntu 12.04.2 LTS x64.

Config: See bottom of this post.

Error: None, but the instance fails to start.

Commands run (after sudo service btsync stop):

---------------------------------

gavin@machine:/etc/btsync$ sudo service btsync start

* Starting P2P file synchronisation daemon(s)... * Autostarting btsync instance 'debconf-default' [ OK ]

* Autostarting btsync instance 'gav' gavin@machine:/etc/btsync$

gavin@machine:/etc/btsync$ ps aux | grep bt

root 27940 0.1 0.0 261560 2028 ? Sl 15:07 0:00 /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/debconf-default.conf

gavin 28011 0.0 0.0 13584 920 pts/6 S+ 15:08 0:00 grep --color=auto bt

-------------------------

It is timing out in start_btsync and generating the error:

log_error "Failed to start $NAME instance $BASENAME - please check the configuration file $CONFIG_DIR/$CONFFILE"

although I don't see an error on the commandline without altering the /etc/init.d/btsync script.

At this point I'm not sure what is wrong so if someone could let me know what the issue might be that would be great.

Thanks,

Gavin

Config script:

//!/usr/lib/btsync/btsync-daemon --config

//

// DAEMON_UID=gavin

//

//

{

"device_name": "Gav - Default Instance",

"storage_path" : "/var/run",

"listening_port" : 0,

"check_for_updates" : false,

"use_upnp" : false,

"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:8887",

"login" : "admin",

"password" : "*****"

}

}

Link to comment
Share on other sites

Hi:

I am trying to setup the BitTorrent Sync server and have found this thread very useful, but not quite enough for me to ge things to fully work.

I have two users on this machine: user1 and user2. I believe I am supposed to create two user config files /etc/btsync/user1.config and /etc/btsync/user2.config - done. I have failed to get the sync to work properly with one of the users.

Here's the config file (they are pretty much the same) I am using, which I created from one of the samples:

// DAEMON_UID=andrew

// DAEMON_UMASK=0007

//

{

"device_name": "DevServer",

"listening_port" : 0,

"storage_path" : "/home/andrew/.mysync",

"check_for_updates" : false,

"use_upnp" : false,

"download_limit" : 0,

"upload_limit" : 0,

"webui" :

{

"listen" : "0.0.0.0:9999"

},

"shared_folders" :

[

{

"secret" : "<deleted>",

"dir" : "/home/andrew/test",

"use_relay_server" : true,

"use_dht" : false,

"search_lan" : true,

"use_sync_trash" : true

}

]

}

Update3:

When I fire up my computer without loging on any user, one of the BTSync configurations is executed (and it is syncing - I confirmed that by adding a file from a remote device, swithinc said device off then logging in - the sync'd file did come through). The second users config does not fire up until and unless I log that user on, and only then because I execute a startup script that basically runs /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/user1.conf. I set this up just to see if I could get it to work - and I can, so the config seems to work, but BT Sync seems unable to read and run with two files (which is clearly wrong).

I'd like both configurations to behave the same way - why does one fire up automatically (great) but the other only do so as/when/if I login *and* execute a script? I am clearly doing something dumb, but I can't see what.

Update4:

It's the strangest thing. If I take both configs onlibe, reset the secret codes inside and restart the service, I can get both to fire up. When I restart the computer, only one (the same one) restarts. If I login, and fire up a terminal, I can start the second service at the command line, but as soon as I restart, I go back to one service. It actually doesn't make any sense to me. :-(

Any help appreciated. :)

Regards,

Edited by wizlon
Link to comment
Share on other sites

Hi Gavin,

So unfortunately there is still an issue. But I'll start again.

...

It is timing out in start_btsync and generating the error:

log_error "Failed to start $NAME instance $BASENAME - please check the configuration file $CONFIG_DIR/$CONFFILE"

although I don't see an error on the commandline without altering the /etc/init.d/btsync script.

I will try to find out, why the error message is not shown. This is definitively a bug that I will try to fix.

Config script:

//!/usr/lib/btsync/btsync-daemon --config

//

// DAEMON_UID=gavin

//

...

"device_name": "Gav - Default Instance",

"storage_path" : "/var/run",

...

And here is your problem: you are running btsync as user "gavin". This means, that all the process runs under this credentials. Obviously the instance must be configured to access only filesystem areas, where the user gavin has the appropriate access. By specifying /var/run as the storage path, you made two fatal mistakes:

  1. The "storage_path" of btsync is a directory where btsync stores his internal databases. Every instance must have a unique storage path, since the filenames of the internal databases are always the same. Obviously the user gavin must have read write access to the storage path. A good storage path would be a subdirectory of the user's home directory like /home/gavin/.btsync/
  2. Beside of the fact that /var/run is writable only for root, this directory should contain only pid, lock and pipe files, since it is intended as a communication area between processes.

This should solve your problem.

Link to comment
Share on other sites

I am trying to setup the BitTorrent Sync server and have found this thread very useful, but not quite enough for me to ge things to fully work.

---

Hi Wizlon,

I will try to help you, but I need some more information. Please add to your reply BOTH configuration files (obviously removing the secrets.

In any case, if both your user will have a web ui, I would suggest at least to remove the predefined folder shares. Although it is possible to work with both web ui and predefined folder shares, it would make things easier to debug.

Link to comment
Share on other sites

Rasperry Pi Dummy instructions (raspbmc) would be wonderfull ... 8) I installed everything manual - but that's not really user friendly ..8)

I'd love to see an instruction for Dummies on installing BTSync on Raspbmc. I tried different tutorials but with no luck on getting it work (nor manually nor by using the srcript)...

Could someone at least confirm BTSync works on Raspbmc (not Raspbian)?

Link to comment
Share on other sites

wizlon,

Something that I've noticed with running two separate instances is that the webui doesn't work properly for both if accessing from the same browser. I would recommend running a different browser for each webui that you want to access. This doesn't address your syncing issue, but once you get things running you will likely run into this problem.

Link to comment
Share on other sites

Hi Wizlon,

I will try to help you, but I need some more information. Please add to your reply BOTH configuration files (obviously removing the secrets.

In any case, if both your user will have a web ui, I would suggest at least to remove the predefined folder shares. Although it is possible to work with both web ui and predefined folder shares, it would make things easier to debug.

Sorry for the delay (travel - my job). I have removed the shared folders and I have the two configuration files as shown below. I logon as user 'andrew', fire up my browser and BTSync shows nothing at either http://localhost:9999/gui/ or http://localhost:9998/gui/. If I open a terminal, cd to /etc/btsync then execute:

/usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/andrew.conf

BTSync fires up and I have a gui at http://localhost:9999/gui/

Now, if I exit (Ctrl-C in the term), the gui disapears - makes sense.

Now if I enter /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/gillian.conf I get an error message "Can't open pid file /home/gillian/.gwbtsync/sync.pid. Permission denied". The folder /home/gillian/.gwbtsync does exist. I can restart the /andrew.conf as before.

I can't explain any of this. I have a new install of Ubuntu 13.04 (I reinstalled it fresh just to see if there was anything amiss with even that.) If you can help me figure out why this is behaving this way, I would really appreciate it.

All I want to do is be able to sync two folders - one for user andrew, one for gillian.

Config files at /etc/btsync/ are: andrew.conf

//!/usr/sbin/btsync-daemon --config

//

// Ā© 2013 YeaSoft Int'l - Leo Moll

// AUTOSTART=all

// DAEMON_UID=andrew

// DAEMON_UMASK=0007

{

"device_name": "A-WiZ btsync Server",

"listening_port" : 0,

"storage_path" : "/home/andrew/.awsync",

"check_for_updates" : false,

"use_upnp" : false,

"download_limit" : 0,

"upload_limit" : 0,

"webui" :

{

"listen" : "0.0.0.0:9999"

}

}

and /gillian.conf:

//!/usr/sbin/btsync-daemon --config

//

// Ā© 2013 YeaSoft Int'l - Leo Moll

// AUTOSTART=all

// DAEMON_UID=gillian

// DAEMON_UMASK=0007

{

"device_name": "G-WiZ btsync Server",

"listening_port" : 0,

"storage_path" : "/home/gillian/.gwbtsync",

"check_for_updates" : false,

"use_upnp" : false,

"download_limit" : 0,

"upload_limit" : 0,

"webui" :

{

"listen" : "0.0.0.0:9998"

}

}

All the directories DO exist. User 'gillian' has full access to the /home/gillian/.gwbtsync folder. User andrew has full access to folder /home/andrew/.awsync

Regards,

andrew

Link to comment
Share on other sites

Hi wizlon,

very well. Let's see what we can do. On a first look, it seems that your config files are OK. So my first question:

I logon as user 'andrew', fire up my browser and BTSync shows nothing at either http://localhost:9999/gui/ or http://localhost:999...:9998/gui/.

It seems evident, that no process is running. Why? After creating the configuration files, you must give a manual command to start the daemons. Have you done it? The btsync daemons are only autostarted at boot, if correct configuration files are available.

Here some useful hints for understanding what is happening. You can verify that the processes are running by executing the following command:


ps axu | grep btsync-daemon

When I enter this commands on my server, I get the following output:


yeasoft-gate2 ~ # ps ax | grep btsync-daemon
yeasoft-gate2 ~ # ps axu | grep btsync-daemon
root 27798 0.0 0.0 6504 628 pts/1 S+ 17:03 0:00 grep --color=auto btsync-daemon
root 30508 0.3 0.5 547208 21776 ? Sl Jul25 43:49 /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/debconf-default.conf
root 30547 0.1 0.2 475432 10864 ? Sl Jul25 21:46 /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/serversync.conf

As you can see, two instances are running as user root. If everything is OK, you should see your two instances running under the respective users. If you want two verify that the instances are listening on the ports you specified, you can enter the following command:


netstat -tlpe | grep btsync-daemon

When I enter this commands on my server, I get the following output:



yeasoft-gate2 ~ # netstat -tlpe | grep btsync-daemon
tcp 0 0 *:26185 *:* LISTEN root 33100655 30508/btsync-daemon
tcp 0 0 yeasoft-gate2.ffm.:8888 *:* LISTEN root 33100668 30508/btsync-daemon
tcp 0 0 *:22144 *:* LISTEN root 33102537 30547/btsync-daemon

Here only one btsync-damon is listening for web connections (port 8888) since one of my instances is configured to have no web UI.

Obviously you have to restart the services after each change to the configuration files:


sudo service btsync restart

...

If I open a terminal, cd to /etc/btsync then execute:

/usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/andrew.conf

BTSync fires up and I have a gui at http://localhost:9999/gui/

Now, if I exit (Ctrl-C in the term), the gui disapears - makes sense.

...

Correct. Everything is working as expected.

...

Now if I enter /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/gillian.conf I get an error message "Can't open pid file /home/gillian/.gwbtsync/sync.pid. Permission denied". The folder /home/gillian/.gwbtsync does exist. I can restart the /andrew.conf as before.

...

Question Nr. 2: Who is "I"? If you are still logged in as user andrew, it is totally obvious, that you (the btsync-damon started with andrew's credentials) is not able to write in gillian's directory ("Permission denied").

And now please do the following.

  1. Make sure that all daemons are stopped (sudo service btsync stop)
  2. Make sure that both configuration files are saved under /etc/btsync
  3. Delete the data directories in the home directories of the two users. btsync will create them with the correct ownership and permissions on the first start
  4. Start the daemons (sudo service btsync start)

And now some final words to anybody reading this thread:

If you do not exactly understand the implications of running one or more instances of a process as a daemon, if you do not know how to find out if processes are running or to find out what they are doing, if you want to use btsync like users do it on Windows or Mac OSX, please take in consideration the option to install the desktop version of btsync because probably this is exactly what you need and what you want. With the desktop version, every user of the system will autostart an instance of btsync upon login without having to bother about configuration files.

The configuration described here seems to be very close to such a scenario. The main difference between the server version and the desktop version of btsync is that the server version runs totally independent from users being logged in to the system. It is mainly intended to be used on headless servers. Having more than one instance running under different credentials implies a good understanding of what happens on a machine.

Link to comment
Share on other sites

Hi wizlon,

very well. Let's see what we can do. On a first look, it seems that your config files are OK. So my first question:

...

Thanks so much for the detailed reply. Here's a line-by-line result of my attempts (I added some comments using // at beginning of lines). There is a very interesting observation (see below):

1. Cold reboot (not changing anything - i.e. same config files I posted earlier).

- no connection at "localhost:9999/gui" (or ...9998/gui)

So I opened a terminal, and here's what I did/found:

andrew@BobCat:/etc/btsync$ cd /etc/btsync

andrew@BobCat:/etc/btsync$ ls -l

total 16

-rwxrwx--- 1 andrew andrew 397 Aug 3 07:19 andrew.conf

-rwxrwx--- 1 gillian gillian 401 Aug 3 07:19 gillian.conf

//so my config files are in place - check.

andrew@BobCat:/etc/btsync$ ps axu | grep btsync-daemon

andrew 2776 0.0 0.0 4428 808 pts/0 S+ 09:12 0:00 grep --color=auto btsync-daemon

// so no process for "gillian", but there is one for andrew - or is there...

andrew@BobCat:/etc/btsync$ netstat -tlpe | grep btsync-daemon

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

// I don't understand this output at all. From the 'ps axu...' line above, I do seem to have a process running, but from netstat it says nothing? I also re-ran this command with root for good measure and it returns with absolutely nothing:

andrew@BobCat:/etc/btsync$ sudo netstat -tlpe | grep btsync-daemon

andrew@BobCat:/etc/btsync$

// So, I now try restarting btsync and this is where it gets INTERESTING:

andrew@BobCat:/etc/btsync$ sudo service btsync restart

* Stopping P2P file synchronisation daemon(s)...

* Stopping btsync instance 'andrew' [fail]

// So, it failed to stop 'andrew'. Is it perhaps because it's not really running? I ask because:-

// I double-checked - still nothing present on localhost:9999/gui or :9998/gui (as expected)

// So, I tried Restarting again and POW - it all works:-

andrew@BobCat:/etc/btsync$ sudo service btsync restart

* Stopping P2P file synchronisation daemon(s)...

* No btsync instance is running.

* Starting P2P file synchronisation daemon(s)...

* Autostarting btsync instance 'andrew' [ OK ]

* Autostarting btsync instance 'gillian' [ OK ]

//And I have a gui present at both localhost:9999/gui and :9998/gui

Before I made any more changes per your last posting, I thought I'd post this to see if it made any sense to you? I am more than happy to proceed with your initial suggestions. I was able to sync from folders created in both gui's - i.e. it seems to work, but only because I issues TWO restart commands I will now (cold) reboot without making changes...done. No gui's, and the folders do not sync - it's all stopped again. It's as if I need to run a command to start the btsync - am I doing something that stupid?

Thanks for all your help!

andrew

PS - if I issue two restart commands again after a cold reboot, it starts to work. So this seems to be reproducible.

Link to comment
Share on other sites

...

Before I made any more changes per your last posting, I thought I'd post this to see if it made any sense to you?

...

I think yes. I suppose, that btsync crashes without any trace when it initially starts. This explains why the daemon scripts try to stop processes that are not really running. I have seen this happen when the memory is not sufficient. But there may be a lot of reasons why this can happen (btsync is still beta software...). Nevertheless please try to give me an answer to the following question:

Is there any specific reason why you decided to install the server version of btsync or do you only have a machine with two active users and you want to use btsync when you are logged on?

Link to comment
Share on other sites

I think yes. I suppose, that btsync crashes without any trace when it initially starts. This explains why the daemon scripts try to stop processes that are not really running. I have seen this happen when the memory is not sufficient. But there may be a lot of reasons why this can happen (btsync is still beta software...). Nevertheless please try to give me an answer to the following question:

Is there any specific reason why you decided to install the server version of btsync or do you only have a machine with two active users and you want to use btsync when you are logged on?

Well I am certainly feeling a little better knowing it's perhaps an unusual bug and not me just screwing up the settings. The good news for me is right now, I am "practicing" using this software (and indeed Ubuntu) in an old laptop (has just 1GB ram, 32-bit processor) whilst my new super-spec'd Systems76 laptop is being built. Hopefully all these problems will go away once I get a modern machine to run Ubuntu on.

To answer your question: I wish to sync a folder that my wife and I use on our Windows Desktop computer to my Ubuntu-based computer (right now my old laptop, very soon to be my new one). We need to have the folder accessible to either of us when we are logged on. Right now, this one folder is on my Windows desktop and we share it as a single user (not very convenient).

* Update:

I played a little more today. If I reboot and logon as user2 ('gillian'), the services are not running, and if I execute sudo ./btsync restart (twice) it does successfully load service for user2 but fails to run service for user1 ('andrew'). Is it possible my permissions are all screwed up?

You've been very helpful sir, I am grateful for your time.

andrew

Link to comment
Share on other sites

So, I think I have identified a bug that affects running btsync with the packaged init script under credentials other than root.

1. btsync expects a per-user PID file sync.pid to get created in the folder indicated by "storage_path" = in the config file - but the init script staticly creates the file in /var/run/<username>.$1.pid - So, when btsync gets launched under a UID/GID other than root, the PID file location needs get changed from /var/run/ to the storage_path location - and needs to happen for each user the daemon is going to spawn under (I think).

For storage_path = /home/<username>/.btsync/

start-stop-daemon --start --quiet --oknodo --pidfile /var/run/btsync.<username>.pid --make-pidfile --chuid <username>:<username> --background --umask 0113 --verbose --exec /usr/lib/btsync/btsync-daemon -- --nodaemon --config /etc/btsync/<username>.conf :

Can't open pid file /home/<username>/.btsync/sync.pid. Permission denied

2. After manually coding the PID path into the init script for testing, it also appears that btsync wants write permissions to this PID file. The PID file created by start-stop-daemon, even with //DAEMON_UID= set in the config file, gets created with ownership 'root:root -rw-rw-r' - This file then needs to be read by btsync, however btsync appears to do an additional check against this PID file to see if its writeable:

start-stop-daemon --start --quiet --oknodo --pidfile /home/<username>/.btsync/sync.pid --make-pidfile --chuid <username>:<username> --background --umask 0113 --verbose --exec /usr/lib/btsync/btsync-daemon -- --nodaemon --config /etc/btsync/<username>.conf :

Can't open pid file /home/<username>/.btsync/sync.pid. Permission denied

ls -al /home/<username>/.btsync/sync.pid :

-rw-rw-r-- 1 root root 6 Aug 4 09:21 sync.pid

If you make the group get set to <username> via chgrp <username> and chmod g+s on the storage_path folder (which ends up giving effective permissions of g+rw to the sync.pid file when it gets created), the issue appears to go away.

For storage_path = /home/<username>/.btsync

chgrp <username> /home/<username>/.btsync

chmod g+s /home/<username>/.btsync

ls -ald /home/<username>/.btsync

drwxrwsr-x 2 xbmc xbmc 4096 Aug 4 09:55 /home/<username>/.btsync/

start-stop-daemon --start --quiet --oknodo --pidfile /home/<username>/.btsync/sync.pid --make-pidfile --chuid <username>:<username> --background --umask 0113 --verbose --exec /usr/lib/btsync/btsync-daemon -- --nodaemon --config /etc/btsync/<username>.conf :

Starting /usr/lib/btsync/btsync-daemon...

By using this application, you agree to our Privacy Policy and Terms.

http://www.bittorrent.com/legal/privacy

http://www.bittorrent.com/legal/terms-of-use

So, the init script is probably going to have to be modified to accomidate this PID requirement of btsync when running under users other than root and with different storage_path variables.

Link to comment
Share on other sites

So, I think I have identified a bug that affects running btsync with the packaged init script under credentials other than root.

Great work. I have been experimenting here too, and I found that I could easily get btsync to run as downloaded from the BitTorrentSync web site, but both of the init scripts (server and desktop) caused me problems. After a lot of terminal work and hair-pulling, I too found permission issues with the PID file (but unlike you, I wasn't smart enough to fix the scripts).

I overcame the PID issue by manually specifying the PID file in a btsync configuration file, and using the same btsync configuration file for launching btsync for users1 and 2 automatically when they login on my system (a novel approach, but it works!). And I had to set permission for users1 and 2 for the PID file too. Only one instance of btsync will run (i.e. whoever logs in first), but either one of them will sync the shared folder I set up (which also contains shared encfs folders). It works like a charm now, and I can sync a shared encrypted folder between two users and my android devices, which is exactly what I am trying to do. I spent ages on this, so I am glad I got a solution - and I am also glad that I may have helped others explore and identify a potential bug too. :)

Your solution is better as it fixes the problem (I go around it - I am not so good with Linux, I am just an ex Windows misfit). I'll probably play with the scripts next week now that you have shown me the way (or we may even get an update :)

Thanks for posting your findings!

Link to comment
Share on other sites

So, I think I have identified a bug that affects running btsync with the packaged init script under credentials other than root.

Unfortunately there is no such a bug, since on all machines on which I test this, it seems to work with any combination of credentials. Explanation:

1. btsync expects a per-user PID file sync.pid to get created in the folder indicated by "storage_path" = in the config file - but the init script staticly creates the file in /var/run/<username>.$1.pid - So, when btsync gets launched under a UID/GID other than root, the PID file location needs get changed from /var/run/ to the storage_path location - and needs to happen for each user the daemon is going to spawn under (I think).

This is not correct. btsync does not expect a per-user PID file. It creates one in the storage path upon launch, and if there is already one in the path, btsync must be able to overwrite it. This file is a text file that contains the PID of the running btsync process in order to allow external programs to quickly know the PID. Obviously btsync needs write access not only to the storage_path but also to all files included there. The storage_path is the very own area of the btsync instance and therefore it must be owned by the user or at least be writable by the user under which the btsync instance is running.

It is nice that in the current version btsync creates this file, since the daemon script may use it in order to check if the instance is running or to stop the instance, but it is quite complicated to find out where the file is located, since you have to parse the configuration files from outside (and this may be error-prone). In addition, older versions of btsync did not create this file and there also was no way to influence, where it was written.

And exactly for this reason, the daemon scripts stores the PID information of the launched btsync daemons in their own PID files stored exactly in the location, where the debian policy requires them to be: /var/run

Also if the PID files in /var/run and the PID files in the storage_path may store the same information, they are maintained by totally separated entities. The daemon scripts are launched by the init process and are running under root credentials. And because of this they ARE ABLE to read and write to /var/run. The btsync instance is running under the specified credentials, and will not be able to write to /var/run, but it will also never need to do it.

NEVER EVER TRY TO MIX UP INSTANCE SPECIFIC STUFF STORED IN THE storage_path WITH THINGS USED BY OTHER PROCESSES OR INSTANCES.

start-stop-daemon --start --quiet --oknodo --pidfile /home/<username>/.btsync/sync.pid --make-pidfile --chuid <username>:<username> --background --umask 0113 --verbose --exec /usr/lib/btsync/btsync-daemon -- --nodaemon --config /etc/btsync/<username>.conf :

Can't open pid file /home/<username>/.btsync/sync.pid. Permission denied

Never do this. The daemon script should never write or create things into the storage_path of an instance of btsync. In this way you create a PID file owned by root:root in the storage_path. Afterwards btsync tries to also create the same file, but cannot write any more, since it has no permissions on this file!

You are mixing up things that have no relationship.

The problem of the user wizlon is something different. It is really strange and I'm still trying to understand what happens on his machine. He says that on system startup only one or sometimes no instance is running, but if he tries to restart the services later on, it works. This shows clearly that the condition that prevents the instances to start exists only in the startup phase of his machine.

Running more than one instance of btsync on one machine requires a lot of memory and does only make sense under very special prerequisites. The typical use case for this is a server in a data center that keeps a copy of data from different users while maintaining the permissions also on the server filesystem.

The use case of wizlon is somewhat particular, since he has only two machines both used by two users. With the standard user installation of btsync, where btsync is only running in the user sessions of a logged in user: if user A is logged in on machine 1 and user B is logged in on machine 2, they will never sync their files, since a sync will only occur, when on both machines the same users are logged on. In such a situation it really makes sense to have btsync running as a daemon despite of which user is logged in. So if someone is working on machine 1, he can be sure, that his files are replicated to machine 2 if machine 2 is running, despite of which user is logged on on machine 2 because both daemons are always running.

Link to comment
Share on other sites

So, I think I have identified a bug that affects running btsync with the packaged init script under credentials other than root.

Unfortunately there is no such a bug, since on all machines on which I test this, it seems to work with any combination of credentials.

And now I will give you the evidence, that there is not bug:

1. First of all, let's create some new dumb users without any particular rights:


yeasoft-gate2 /etc/btsync # useradd -m user1
yeasoft-gate2 /etc/btsync # useradd -m user2
yeasoft-gate2 /etc/btsync # useradd -m user3

2. Let's check the home directories:



yeasoft-gate2 /etc/btsync # ls -la /home
total 24
drwxr-xr-x 6 root root 4096 Jul 17 00:04 .
drwxr-xr-x 22 root root 4096 Jul 7 18:07 ..
drwxr-xr-x 4 leo leo 4096 Feb 25 15:01 leo
drwxr-xr-x 3 user1 user1 4096 Aug 6 15:51 user1
drwxr-xr-x 3 user2 user2 4096 Aug 6 15:51 user2
drwxr-xr-x 3 user3 user3 4096 Aug 6 15:51 user3

3. Are they empty?



yeasoft-gate2 /etc/btsync # ls -la /home/user*
/home/user1:
total 20
drwxr-xr-x 2 user1 user1 4096 Aug 6 15:52 .
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

/home/user2:
total 20
drwxr-xr-x 2 user2 user2 4096 Aug 6 15:52 .
drwxr-xr-x 6 root root 4096 Jul 17 00:04 ..
-rw-r--r-- 1 user2 user2 220 Apr 3 2012 .bash_logout
-rw-r--r-- 1 user2 user2 3486 Apr 3 2012 .bashrc
-rw-r--r-- 1 user2 user2 675 Apr 3 2012 .profile

/home/user3:
total 20
drwxr-xr-x 2 user3 user3 4096 Aug 6 15:52 .
drwxr-xr-x 6 root root 4096 Jul 17 00:04 ..
-rw-r--r-- 1 user3 user3 220 Apr 3 2012 .bash_logout
-rw-r--r-- 1 user3 user3 3486 Apr 3 2012 .bashrc
-rw-r--r-- 1 user3 user3 675 Apr 3 2012 .profile

Fine. Only the standard stuff from /etc/skel.

4. Now let's create some simple configuration files and then we look at the contents:



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"
}
}

yeasoft-gate2 /etc/btsync # cat user2.conf
//!/usr/sbin/btsync-daemon --config
//
// DAEMON_UID=user2
// DAEMON_GID=user2
//
{
"device_name": "user2@server.domain.lan",
"listening_port" : 0,
"storage_path" : "/home/user2/.btsync",
"pid_file" : "/home/user2/.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:61010",
"login" : "admin",
"password" : "blablabla"
}
}

yeasoft-gate2 /etc/btsync # cat user3.conf
//!/usr/sbin/btsync-daemon --config
//
// DAEMON_UID=user3
// DAEMON_GID=user3
//
{
"device_name": "user3@server.domain.lan",
"listening_port" : 0,
"storage_path" : "/home/user3/.btsync",
"pid_file" : "/home/user3/.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:61011",
"login" : "admin",
"password" : "blablabla"
}
}

Great! Every instance has it's own credentials, directories, ports, etc. Absolutely no interference between them...

5. And now for your viewing pleasure....



yeasoft-gate2 /etc/btsync # service btsync restart
* Stopping P2P file synchronisation daemon(s)...
* Stopping btsync instance 'debconf-default' [ OK ]
* Stopping btsync instance 'serversync' [ OK ]
* Starting P2P file synchronisation daemon(s)...
* Autostarting btsync instance 'debconf-default' [ OK ]
* Autostarting btsync instance 'serversync' [ OK ]
* Autostarting btsync instance 'user1' [ OK ]
* Autostarting btsync instance 'user2' [ OK ]
* Autostarting btsync instance 'user3' [ OK ]

Whoa! Apparently our 3 new instances are now running... Are they really?



yeasoft-gate2 /etc/btsync # pgrep btsync-daemon
27831
27873
27955
28039
28144

5 Processes running. Great. Really?



yeasoft-gate2 /etc/btsync # ps axu | grep btsync-daemon
root 27831 1.5 0.2 400268 9520 ? Sl 15:58 0:03 /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/debconf-default.conf
root 27873 0.1 0.0 394836 3832 ? Sl 15:58 0:00 /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/serversync.conf
user1 27955 0.0 0.0 260848 2192 ? Sl 15:58 0:00 /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/user1.conf
user2 28039 0.0 0.0 260848 2196 ? Sl 15:58 0:00 /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/user2.conf
user3 28144 0.0 0.0 260848 2196 ? Sl 15:58 0:00 /usr/lib/btsync/btsync-daemon --nodaemon --config /etc/btsync/user3.conf
root 31590 0.0 0.0 6504 624 pts/1 S+ 16:02 0:00 grep --color=auto btsync-daemon

Yes. They are not only running. They are running under the desired credentials. Let's see the contents of the home directories...



yeasoft-gate2 /etc/btsync # ls -la /home/user*
/home/user1:
total 24
drwxr-xr-x 3 user1 user1 4096 Aug 6 15:58 .
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
drwxr-xr-x 2 user1 user1 4096 Aug 6 15:58 .btsync
-rw-r--r-- 1 user1 user1 675 Apr 3 2012 .profile

/home/user2:
total 24
drwxr-xr-x 3 user2 user2 4096 Aug 6 15:58 .
drwxr-xr-x 6 root root 4096 Jul 17 00:04 ..
-rw-r--r-- 1 user2 user2 220 Apr 3 2012 .bash_logout
-rw-r--r-- 1 user2 user2 3486 Apr 3 2012 .bashrc
drwxr-xr-x 2 user2 user2 4096 Aug 6 15:58 .btsync
-rw-r--r-- 1 user2 user2 675 Apr 3 2012 .profile

/home/user3:
total 24
drwxr-xr-x 3 user3 user3 4096 Aug 6 15:58 .
drwxr-xr-x 6 root root 4096 Jul 17 00:04 ..
-rw-r--r-- 1 user3 user3 220 Apr 3 2012 .bash_logout
-rw-r--r-- 1 user3 user3 3486 Apr 3 2012 .bashrc
drwxr-xr-x 2 user3 user3 4096 Aug 6 15:58 .btsync
-rw-r--r-- 1 user3 user3 675 Apr 3 2012 .profile

OK. Every process has created his own storage_path... Let's take a close look:



yeasoft-gate2 /etc/btsync # ls -la /home/user1/.btsync/
total 108
drwxr-xr-x 2 user1 user1 4096 Aug 6 15:58 .
drwxr-xr-x 3 user1 user1 4096 Aug 6 15:58 ..
-rw-r--r-- 1 user1 user1 6 Aug 6 15:58 btsync.pid
-rw-r--r-- 1 user1 user1 2400 Aug 6 15:58 settings.dat
-rw-r--r-- 1 user1 user1 0 Aug 6 15:58 sync.log
-rw-r--r-- 1 user1 user1 91220 Aug 6 15:58 webui.zip

Fine. Everything as expected. And what's about the PID files of the daemon scripts?



yeasoft-gate2 /etc/btsync # ls -la /var/run/*btsync*
-rw------- 1 root root 6 Aug 6 15:58 /var/run/btsync.debconf-default.pid
-rw-r--r-- 1 root root 6 Aug 6 15:58 /var/run/btsync.serversync.pid
-rw-r--r-- 1 root root 6 Aug 6 15:58 /var/run/btsync.user1.pid
-rw-r--r-- 1 root root 6 Aug 6 15:58 /var/run/btsync.user2.pid
-rw-r--r-- 1 root root 6 Aug 6 15:58 /var/run/btsync.user3.pid

Everything as expected. Buuuuuut..... are all the processes really listening on the web ui ports?



yeasoft-gate2 /etc/btsync # netstat -tlpe | grep btsync-daemon
tcp 0 0 *:26185 *:* LISTEN root 55661403 27831/btsync-daemon
tcp 0 0 *:28878 *:* LISTEN user1 55664345 27955/btsync-daemon
tcp 0 0 *:44975 *:* LISTEN user3 55664443 28144/btsync-daemon
tcp 0 0 *:61009 *:* LISTEN user1 55664358 27955/btsync-daemon
tcp 0 0 *:61010 *:* LISTEN user2 55661479 28039/btsync-daemon
tcp 0 0 *:61011 *:* LISTEN user3 55664456 28144/btsync-daemon
tcp 0 0 yeasoft-gate2.ffm.:8888 *:* LISTEN root 55661416 27831/btsync-daemon
tcp 0 0 *:22144 *:* LISTEN root 55661418 27873/btsync-daemon
tcp 0 0 *:27558 *:* LISTEN user2 55661466 28039/btsync-daemon

They do.

Finally I should mention, that this server has a lot of memory, so it is not a problem starting 5 instances of btsync.... at least if they do not have to replicate millions of files....

Link to comment
Share on other sites

Ok, I think I have identified why some users (including myself) are experiencing this as a bug.

"pid_file" : "/home/<ussername>/.btsync/btsync.pid",

When this parameter is supplied in the config file, everything works perfectly. However, when it is not supplied (when you are also spcifying UID/GID and the storage_direcctory) everything stops working - but only when run via the init script. It works just fine if you run btsync-daemon --config=/etc/btsync/<config without the pid_file parameter>. However the init script simply silently fails to start the daemon when it tries to run a config without this set.

I don't know if this is a bug in btsync (I doubt it as it runs just fine from the command line), but it would be really helpful if the init script did some sanity checking to see if a user has created a config that is impossable for the init script to start (such as when the UID is specified with a storage_dir and no pid_file).

So, I guess please inturpet this as a feature request.

Thanks for your help identifiying this, and thanks for providing the packages!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.