You are not logged in.

#1 2009-01-23 04:59:27

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

[Solved] Zombie Process created... fastcgi script....

I have lighttpd with fastcgi to execute a webpy script. This webpy script calls a python script. This python script it dying as a zombie. I have no idea what the problem is. If I run the webpy script by itself everything works.

lighttpd.conf

fastcgi.debug = 1

fastcgi.server = ( 
    "/radio.py" =>     
     (( 
         "socket" => "/tmp/fastcgi.socket",
             "bin-path" => "/srv/http/radio/radio-wrapper.sh",
             "bin-environment" => (
                       "REAL_SCRIPT_NAME" => ""
             ),
             "check-local" => "disable",
        "max-procs" => 1
    )),
    ".php" =>
      ( "localhost" =>
        (
          "socket" => "/tmp/php-fastcgi2.socket",
          "bin-path" => "/usr/bin/php-cgi",
              "check-local" => "disable"
        )
      )
)

Webpy Script

#!/usr/bin/env python
import web
import os
import glob
import time
import subprocess
import radiofun #Functions that generate html code


#debug=True

urls = (
  '/', 'index',
  '', 'index',
  '/kill', 'kill',
  '/stream', 'stream',
  '/add', 'add'
)

#web.config.debug = False
web.config.debug = True

app = web.application(urls, globals())

class index:
    def GET(self):
        web.header("Content-Type","text/html; charset=utf-8") 
        output = """
            <html>
            <head>
                <title>Record Sirius Radio</title>
                <link rel="stylesheet" type="text/css" href="./static/style.css" />
                <meta http-equiv="refresh" content="15" >
            </head>
            <body>
            <div class="content">
        """
        output += '<h1>Audio Recorder</h1>'
        output += '<h2>A Radio Recoder for Sirius Radio</h2>'

        
        results = radiofun.genTable()

        InProgress = results[1]
        output += results[0]
         

        if InProgress:
            pass
        else:
            if os.popen("ps aux | grep ices | grep -v grep | gawk '{ print $2 }' | head -n 1").readlines():
                output += """<br>The Stream server is running...<a href="./stream?do=stop" style="font-weight: bold;">Stop</a> or
                <a href="http://10.20.1.2:8010/satradio.ogg.m3u" style="font-weight: bold;">click to listen.</a>"""
            else:
                output += """<br><a href="./stream?do=start">Click to start Stream server</a>"""

        output += """<div class="newRec"><a href="./add">Add New Recording</a></div>"""
        
        output += """</div></body></html>"""
        
            #web.seeother('/')

    return output

class add:
    def GET(self):
        web.header("Content-Type","text/html; charset=utf-8") 
    
        output=("""
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
            <head>
                <title>Record Sirius Radio</title>
                <link rel="stylesheet" type="text/css" href="./static/style.css" />
            </head>
            <body>
            <div class="content"><div class="containerAdd">
            """)
        
        #Header
        output+=('<h1>Add a Recording</h1><br/>')
        
        #Start of Form
        output+=("<form method='post' action='./add'>")

        #Hour Section   
        output += "Start Time:"
        output += radiofun.genHours('StartHour', 'Start')

        #Minutes Section    
        output+= ':'
        output+= radiofun.genMinutes('StartMinutes')
        
        output+=('<input type="checkbox" name="StartNow" value="True"/>Start Now')

        output+=('<br/>')    
        output+=('<span>End Time: </span>')
        output+=(radiofun.genHours('EndHour', 'End'))

        #Minutes Section    
        output+=(':')
        output+=radiofun.genMinutes('EndMinutes')
       
        output+=('<br/>')
        output+=('<br/>')
        output+=('Folder Name:<input type="text" name="DIR" value="folder" />')
        output+=('<br/>')
        output+=('File Name: &nbsp<input type="text" name="FileName"i value="file" />.mp3<br/><br/>')
        
        output+=('Rate: ' + radiofun.genRate('Rate'))
        output+=(' ')
        output+=('Channel: ' + radiofun.genChannel('Channel'))


        output+= """
        <br/><br/>
        <center>
        Split Time:
        <input type='text' name='SplitTime' value="0.00" size="4" />
        </center>
        """
        output+= '<br/>'
        #print '''<input type='submit' value='submit' />'''
        output+= '''<center><input type='submit' value='Submit'  class="submitButton"/></center>'''


        output+=('</form>')
        output+=('<div class="goBack"><a href="./">Go Back</a></div>')

        output+= """</div></div><p style="font-size: 10px; width: 700px; margin:auto;">*You can not have two recording going at the same time!</p>"""
        output+=('</body></html>')

    return output

    def POST(self):
        i = web.input(StartNow=None)

        StartTime = str(i.StartHour) + ':' + str(i.StartMinutes)
        EndTime = str(i.EndHour) + ':' + str(i.EndMinutes)
        DIR = '/home/steve/' + str(i.DIR)
        FileName = str(i.FileName)+".mp3"
        StartNow = i.StartNow
        Rate = i.Rate
        Channel = i.Channel
        SplitTime = i.SplitTime
        Error=False


        try:
            float(SplitTime)
        except ValueError:
            Error=True

        subprocess.Popen(['/usr/bin/whoami'])

        if not(Error):
            if StartNow=="True":
                subprocess.Popen(['/home/bin/audio-recorder.py', '-E', EndTime, '-d', DIR, 
                    '-f', FileName, '-t', i.SplitTime, '-c', Channel, '-g', '-r', Rate])
            else:
                subprocess.Popen(['/home/bin/audio-recorder.py', '-E', EndTime, '-S', StartTime, '-d', DIR, 
                    '-f', FileName, '-t', i.SplitTime, '-c', Channel, '-r', Rate])
    time.sleep(1)
        web.seeother('/')

class kill:
    def GET(self):
        i = web.input()
        filename = i.filename
        #print i.filename
       
        fline=None
        sline=None
        fpid=None
        frecpid=None


        try:
            FILE = open(filename,"r")
            fline=FILE.readline()
            sline=FILE.readline()
        except IOError:
            print """
            <script language="javascript">
                MsgBox("No such file or corrupt file!");
            </script>
            """
       
        if fline=="#PythonPID#PID#Filename#shour#sminute#endhour#endminute\n": #Recording in progress
            fpid = sline.split()[0]
            frecpid = sline.split()[1]
        elif fline=="#PythonPID#Filename#shour#sminute#endhour#endminute\n": 
            fpid = sline.split()[0]

        if fpid:
            try:       
                os.kill(int(fpid), 15) #KILL PID
            except OSError:
                pass
        if frecpid:
            try:
                os.kill(int(frecpid), 15) #KILL PID2
            except OSError:
                pass
        
        if fpid or frecpid:
            os.remove(filename)
        print('</html>')
        time.sleep(1)
        web.seeother('/')

class stream:
    def GET(self):
        i = web.input() 

        if i.do == "start":
            radiofun.start_stream()
        elif i.do == "stop":
#            print 'Stopping Stream'
            radiofun.stop_stream()

        time.sleep(1) #Sleep for 1 sec, to give system time to update
        web.seeother('/')


if __name__ == "__main__":
    #web.webapi.internalerror = web.debugerror
    #web.webapi.notfound = my_notfound
    #web.wsgi.runwsgi = lambda func, addr=None: web.runfcgi(func, addr)
    #app.run(urls, globals(),web.reloader)
    app.run()

subprocess.Popen(['/home/bin/audio-recorder.py', '-E', EndTime, '-S', StartTime, '-d', DIR,   '-f', FileName, '-t', i.SplitTime, '-c', Channel, '-r', Rate])
That is how I'm calling the script and that script is zombing.

ps aux

[root@mongo ~]# ps aux | grep Z
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
steve     2159  0.0  0.0      0     0 ?        Z    23:47   0:00 [python] <defunct>

If I run python radio.py is starts its own http server, and everything runs fine. All the commands execute without becoming zombies or anything like that.

Any help would be great. I am so lost!!

Last edited by pyther (2009-01-23 13:08:03)


Website - Blog - arch-home
Arch User since March 2005

Offline

#2 2009-01-23 12:53:47

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved] Zombie Process created... fastcgi script....

I don't know if it will solve anything, but it seems interesting to try:

How to daemonize

Offline

#3 2009-01-23 13:07:15

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Re: [Solved] Zombie Process created... fastcgi script....

Thanks, that definitely is interesting and I will have to look at implementing it when I do my next fixup of my current code.

I did a bit more debugging and ran /usr/bin/id. The results showed that the user was "steve" but the group was "root". I thought lighttpd was suppose to default to nobody. Anyways I modified lighttpd.conf and set the group to users and everything is working now. o_o.

Last edited by pyther (2009-01-23 13:07:29)


Website - Blog - arch-home
Arch User since March 2005

Offline

Board footer

Powered by FluxBB