a question about pid files twonky and linux

General discussion about the media server. Feature requests. Hints, tips and tricks.
Locked
User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag
a question about pid files twonky and linux

Post by phibertron » Mon Aug 27, 2012 9:37 pm

On one hand I think I understand why a PID file is needed
but on the other, I cant see why one would be needed,
as its not like a process doesnt get one assigned to it

For example I see it always used in the twonky scripts
PIDFILE=/var/run/mediaserver.pid

is the purpose of the pid to better create script logic to do start|stop|restart|reload|status actions?
or is there some underlying kernel actions that I am unware of that operate better with it?
as my option was to just create some of my own, to launch each instance of twonky with
but its the number used in it that worries me
I cant imagine that this is some random number

The reason I ask
I just got done doing my testing of multiple instances of twonky server 7 on windows, it went very well
and its about time I try this on my nas
I had started out there, but ran into some issues, and moved onto testing the process in windows
so before I doing a lot of back and forth


I'm all ears to any info or experiences on the topic that could share
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
parnott
Posts:326
Joined:Mon Sep 20, 2010 9:55 pm
AV Hardware:Twonky, WDTV Live, XBMC (Linux & Windows)

Re: a question about pid files twonky and linux

Post by parnott » Mon Aug 27, 2012 11:13 pm

PID files are a standard convention in Linux (I think it goes back even farther to Unix). They are generally used by server process's.

A pid file contains a process's PID (i.e. the Process ID). These files are generally used in startup/shutdown/reload etc. scripts to find a process's PID and determine such things as- is an instance already running , has the process crashed, shut down the process cleanly. They can also be used from the command shell, e.g. to kill twonkyserver use-
kill `cat /var/run/twonkyserver.pid`

So yes the number in a pid file is important.

If you want to run multiple instances of twonkyserver on Linux make sure you use the -instance command line option. So for example when I ran both Twonky 4 and Twonky 6 concurrently, one was started with -instance 4 and the other with -instance 6. The number does not matter except that I recall it has to be a single digit. The effect is to create various instance specific files, e.g. an instance specific ini file and I think an instance specific pid file.
Also don't try and and do multple instances from the same startup/shutdown script. Create a unique script for each instance. These can however call back into a common script and pass in the instance number.

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

Re: a question about pid files twonky and linux

Post by phibertron » Mon Aug 27, 2012 11:48 pm

Thanks for the info
been working on windows platform for a long time
one of these I'll get the how to admin linux from a windows admin perspective
most things in either seem relative
its the why do they do that, not the how do they do that, is where I "usually" get stuck
So yes the number in a pid file is important.
that makes sense,
I'd imagine, as long as the number in the pid is not being used in another pid
or by another process currenlty running
I could pick some very larger number to avoid any conflicts
Also don't try and and do multple instances from the same startup/shutdown script. Create a unique script for each instance. These can however call back into a common script and pass in the instance number.
I first tried it with the multiple instances from the twonky.sh script
I just replicated the execute line, one for each instance
and while it did work, there were other things that didnt look right
and yeah, when I went to stop it, it only killed one instances

thanks again for the info
when I get something working, I'll pass it along
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
parnott
Posts:326
Joined:Mon Sep 20, 2010 9:55 pm
AV Hardware:Twonky, WDTV Live, XBMC (Linux & Windows)

Re: a question about pid files twonky and linux

Post by parnott » Tue Aug 28, 2012 12:46 am

I'd imagine, as long as the number in the pid is not being used in another pid
or by another process currenlty running
I could pick some very larger number to avoid any conflicts
You cannot make up your own PID number. The way it works is-
1. The startup script starts the Twonky service (in 7.x this is twonkystarter).
2. The Kernel assigns a PID and starts the process.
3. Twonky reads its PID from the kernel and writes it to the pid file.

The kernel assigns PID's. And, you cannot tell the Kernel what PID to assign. You have to work with the PID that was assigned by the Kernel to the process.

Why does Linux do it this way- well apart from the fact that it has always been done this way, think about 2 instances of the same server. The only thing that the intsances of the servers and the startup/shutdown scripts have in common in a Linux environment is a pid file unique to each instance. That is how it is designed to work.

I think what you may be missing is the -instance command option. That is how Twonky keeps each instance seperate, or at least it used to. The Kernel does not know about this. It just assigns a unique PID to each instance.

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

Re: a question about pid files twonky and linux

Post by phibertron » Tue Aug 28, 2012 1:19 am

I did have it working on the nas, with -instance # for each instance
ran into some self induced chaos with the twonkyserver.ini
trying to see what the relationship with twonkyproxy was to an instance
I now know, twonkyproxy is not instance dependant, which is awesome
havent played around with twonkywebdav with multiple instances yet

of interest, havent tried this switch yet on the nas,
but windows twonky 7 is using twonkystarter -serviceversion #
but -instance still works too

the pid's and processes from a kerne perspective I get

It when I view the contents of the actual /tmp/mediaserver.pid
it has a number in it, thats the number im refering to.
not sure where the number comes from
is the number in there changing each time twonky script starts
and getting put in there by the script/kernel
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

Re: a question about pid files twonky and linux

Post by phibertron » Tue Aug 28, 2012 1:28 am

I think I know the answer

I have to create a pid file for each process I want, and whatver gets put in there is the pid of the current running process
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

Re: a question about pid files twonky and linux

Post by phibertron » Tue Aug 28, 2012 1:50 am

parnott, thanks again for the spoon feeding =)
I am now a little more clued in to how the pid files work

top -p $(pgrep -d',' twonky)

7225 root 21 1 44352 27m 3840 S 50.6 11.1 0:28.75 twonkyserver
7223 root 21 1 3840 1792 1280 S 0.0 0.7 0:00.00 twonkystarter
7226 root 21 1 7808 4480 2624 S 0.0 1.8 0:00.17 twonkyproxy

/var/run - > /tmp mediaserver.pid

7223

PS
This link was helpfull for the other part of how it works for /etc/init.d and /etc/rc#.d

http://www.debian-administration.org/articles/212
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

Locked