Forum
[IDEA] Pause download package when video is playing. - Printable Version

+- Forum (http://forum.xbian.org)
+-- Forum: Community (/forum-5.html)
+--- Forum: Support the project (/forum-11.html)
+---- Forum: Contribute (/forum-34.html)
+---- Thread: [IDEA] Pause download package when video is playing. (/thread-374.html)

Pages: 1 2 3


RE: Pause download package when video is playing. - adepssimius - 8th Feb, 2013 02:26 AM

This looks great! When are we gonna see a working package with this?


RE: Pause download package when video is playing. - SolGarlic - 3rd Mar, 2013 12:52 AM

(6th Feb, 2013 05:48 AM)Trinket Wrote:  Sorry for not posting earlier, I had a problem with the Hard drive used by the Raspberry (I'm still fixing it).
Regarding the script, I set it to 1minute (60000) and deleted the init function and it worked as you told!
Thank you very much for your help

Hi,
I'm having some difficulties following your steps: where is the startall.py? where is the last version of the addon.xml?
Can you please post the last versions of all files, or the final tutorial?
Does it work with the latest download package?
I'm eager to try your great work!


RE: Pause download package when video is playing. - Trinket - 3rd Mar, 2013 06:26 AM

I will try to explain it the best I can!
Here is the folder with all the files needed in it https://www.dropbox.com/sh/jrxem38vzn8aybq/3-Ws7QcygB?m
the folder where you store those files should be named service.procmanager and must be storen in:
/home/xbian/.xbmc/addons/
Make sure all is set to be executable and that only root can write the files (especially the ones inside Resources).
In order for it to work you must start all the processes related to downloads as a group named "download" (you must create it) that's easily done if you modify the start-stop-daemon inside the init scripts of each process.
These are the steps involved:
You create a new group with:
Terminal
sudo addgroup --system download
Then add users to it with:
Terminal
sudo adduser "username" download
You must add each user that will start downloads to this group.
Then you must edit the init script of each process to run them in this group.
Go to the folder /etc/init.d and modify the init scripts (they are almost all named the same as the program, sickbeard, couchpotato...)
For example this is my start-stop-daemon line for couchpotato:
Code:
start-stop-daemon -N 10 -d $APP_PATH -c $RUN_AS:$GROUP --start --background --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
The option that you'r searching for is "-c" or "--chuid".
EDIT:Add also GROUP=download where all the other variables are set (or anywhere on the file)

Once you do that, you must allow the files inside resources folder to be executed with privileges without password input.
You do that with the visudo command.
Terminal
sudo visudo
Once there, supossing xbian is the user that starts xbmc, you must add this lines to the end of the file:
Code:
xbian ALL=(ALL) NOPASSWD: /usr/bin/python /home/xbian/.xbmc/addons/service.procmanager/resources/startall.py
xbian ALL=(ALL) NOPASSWD: /usr/bin/python /home/xbian/.xbmc/addons/service.procmanager/resources/stopall.py
If you have any problem just tell me and I will try to be more detailed. Maybe you have problems with the init scripts not using the start-stop-daemon, if so just ask me and i can upload mine's.


RE: Pause download package when video is playing. - SolGarlic - 3rd Mar, 2013 07:23 AM

WOW!!!
Thanks! and If I have any issue I will report back!

UPDATE:
OK, tried it but apparently didn't work:
logged in as root (didn't need to use "sudo su")
Moved the folder to the correct location (including the subfolder) and "chmod 755"everything (noticed now that the scripts in "resource" are still 777. Should this be the problem? - UPDATE2: changed and keeps the same)

Created the group and added "xbian" to it. Using "top", it was xbian that was creating the processes.
Should I also add "root"? I noticed now that "root" is the one that started transmission-daemon. (UPDATE2: changed and keeps the same)

Then I changed the init.d scripts for sickbeard and transmission. It should be enough to try, and I only use one more (nzbget) for which I didn't find the correct location to make the change.
Just made sure both modified scripts had the "$RUN_AS:$GROUP" like you mentioned.

And then after adding the two lines in the end was easy...

But after the "dim" screensaver starts, both processes continue running...
I suppose they should be stopped, right?

Anyway thanks again for your tutorial and help.
I really hope CurlyMo integrates this with the download package!


RE: Pause download package when video is playing. - CurlyMo - 3rd Mar, 2013 07:29 AM

Why did you create separate groups/users and not just use the xbian:xbian?


RE: Pause download package when video is playing. - Trinket - 3rd Mar, 2013 08:12 PM

The way my script works is detecting which processes are running by the group "download" and send them a SIGSTOP to all of them, so make sure all the processes you want to stop are created by one group that's only for that, and that group must be named "download" (you can change that in the scripts inside resources)
What you see with "top" is the user that's creating the process, not the group. To see the processes that my script is going to stop run the command:
Terminal
ps -g download
Run the command and tell me if there is any process running under that group.


RE: Pause download package when video is playing. - SolGarlic - 3rd Mar, 2013 08:23 PM

Apparently none...
Did you install the latest download package with alpha5? If so can you send me the sickbeard and transmission init.d scripts?

This is the result of the only line I changed in sickbeard script:
"start-stop-daemon --background -d $APP_PATH -c $RUN_AS:$GROUP $EXTRA_SSD_OPTS --start --pidfile $PID_FILE --exec $DAEMON -- ...."

I think I did the change you mentioned inside these scripts, but found it weird to be so simple and with no reference to "download".

(3rd Mar, 2013 08:12 PM)Trinket Wrote:  Run the command and tell me if there is any process running under that group.



RE: Pause download package when video is playing. - Trinket - 4th Mar, 2013 04:43 AM

I didn't install the download package, I installed them myself Undecided
But here is my init.d scripts, it should be all you need for it to work!
I also start my daemons with low priority (10) and low I/O priority (best-effort).
These are my init.d scripts:
-sabnzbd
-sickbeard
-couchpotato
-transmission-daemon

The -N 10 is applied to all the daemons in order to have terminal commands executed faster.
The -I best-effort:6 parameter in sabnzbd and transmission lowers the I/O usage so that they don't interfere too much if I wish to see content from my PC streaming through the HDD attached to the Raspberry
All my daemons are executed by different users, so you may have to change them, but I have declared them as a variable so it shouldn't be a problem.
Hope it works now!
EDIT:Oh, forgot to mention, did you set anywhere in your init.d script "GROUP=download" you must do so, preferably at the start of the document where the rest of the variables are set!


RE: Pause download package when video is playing. - SolGarlic - 4th Mar, 2013 07:32 AM

I will try, but in your script you only have "GROUP=${GROUP}". The reference to the "download" group is made someplace else?
I will try simply with group=download...

UPDATE:
OK now with "ps -g download" I already see "python" for sickbeard and it seems to be working!!!
I also use transmission and nzbget, but as these have a different construction inside the script I couldn't manage to do it yet.
the download package original scripts are in this zip: scripts.zip ,along with my working sickbeard script.
Can you find a more elegant and uniform way of making your scripts work, so that any package user can also use your scripts?

(4th Mar, 2013 04:43 AM)Trinket Wrote:  I didn't install the download package, I installed them myself Undecided
But here is my init.d scripts, it should be all you need for it to work!
I also start my daemons with low priority (10) and low I/O priority (best-effort).
These are my init.d scripts:
-sabnzbd
-sickbeard
-couchpotato
-transmission-daemon

The -N 10 is applied to all the daemons in order to have terminal commands executed faster.
The -I best-effort:6 parameter in sabnzbd and transmission lowers the I/O usage so that they don't interfere too much if I wish to see content from my PC streaming through the HDD attached to the Raspberry
All my daemons are executed by different users, so you may have to change them, but I have declared them as a variable so it shouldn't be a problem.
Hope it works now!
EDIT:Oh, forgot to mention, did you set anywhere in your init.d script "GROUP=download" you must do so, preferably at the start of the document where the rest of the variables are set!



RE: Pause download package when video is playing. - Trinket - 4th Mar, 2013 07:51 AM

Yeah you are right! But that's only for sickbeard, that script is a bit different because sickbeard gets it's default values from another file where the variables are declared. You can see that here:
Terminal
# Source SickBeard configuration
if [ -f /etc/default/sickbeard ]; then
. /etc/default/sickbeard
else
echo "/etc/default/sickbeard not found using default settings.";
fi
In /etc/default/sickbeard I have declared the variable "GROUP=download" and that variable is called back again, It's unnecesary to do declare it again in the init script, I could use it directly as it's imported from the default file, I do so just to remember that variable exists.
Pay attention to the init scripts, just sickbeard is different.
Here are the default variables for sickbeard:
/etc/default/sickbeard
Sorry for that!
You could just do:
Terminal
"start-stop-daemon --background -d $APP_PATH -c $RUN_AS:download $EXTRA_SSD_OPTS --start --pidfile $PID_FILE --exec $DAEMON
What I was trying to explain you to do was just in order to make it easier to replace if you for whatever reason wished to do so. But maybe it's easier if you just add ":download"


RE: Pause download package when video is playing. - SolGarlic - 4th Mar, 2013 10:14 AM

Thanks for your help! I got it working also with transmission.
I just can't manage to do it with NZBGET because it is completely different from the others (doesn't use start-stop-daemon).
Can you send me your script as well?

UPDATE: I noticed now that you use SABNZBD, so you probably don't use NZBGET...
If you have time to waste, take a look at the original script I posted above, but these 2 should be enough to prevent the stutter...


RE: Pause download package when video is playing. - Trinket - 4th Mar, 2013 10:23 AM

Sorry, I use sabnzbd. Search for an init script that uses start-stop-daemon (you may find it). Also, if you are running NZBGET with a user just for it, you may set the "download" group to be the primary one or the only one and it would automatically be run by it.
You can change the default/primary group of a user with the following command
Terminal
usermod -a -g "group" "user"



Re: Pause download package when video is playing. - min - 19th Mar, 2013 04:09 AM

Using this idea is it possible to have a script or bash command to start/stop a group of processes, ie sickbeard, couch potato & a couple of other python programs?


RE: Pause download package when video is playing. - Trinket - 20th Mar, 2013 06:11 AM

With this script you can stop whichever process you want. The only requisite is that all of them are executed by the same group.
In this case "download" is the group.
It's a bit complicated to get it working (If you'r not used to linux) because I wanted to make sure that it was a safe method, and that's why I had to edit the sudoers file (With the visudo command).
But once you get it working, it's really easy to add new processes to the "download" group so that they are also stopped.


Re: Pause download package when video is playing. - min - 21st Mar, 2013 02:03 AM

The reason I ask is that processes like nzbget & sab don't cause problems unless another of mine has sent them a job, so if I freeze/kill those processes with a remote command (I use android app 'server assistant') or an xbmc add-on, then playback is perfect.

Rather than changing their group could I just add them by name, sbeard & couchpot etc?

I have added them all to xbian group.