Run web.py as a daemon

I have a simple web.py program for loading data. On the server, I do not want to install apache or any web server.

I am trying to use it as a help desk with http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

And subclassification: (from http://www.jejik.com/files/examples/daemon.py )

class Daemon:
    def start(self):
        """
        Start the daemon
        """
        ... PID CHECKS....

        # Start the daemon
        self.daemonize()
        self.run()
#My code
class WebService(Daemon):
        def run(self):
            app.run()

if __name__ == "__main__":
    if DEBUG:
        app.run()
    else:
        service = WebService(os.path.join(DIR_ACTUAL,'ElAdministrador.pid'))
        if len(sys.argv) == 2:
            if 'start' == sys.argv[1]:
                service.start()
            elif 'stop' == sys.argv[1]:
                service.stop()
            elif 'restart' == sys.argv[1]:
                service.restart()
            else:
                print "Unknown command"
                sys.exit(2)
            sys.exit(0)
        else:
            print "usage: %s start|stop|restart" % sys.argv[0]
            sys.exit(2)

However, the web.py software does not load (that is: the service is not listening)

If I call it directly (i.e. does not use the daemon code), work fine.

+5
source share
4 answers

I finally found the problem.

Web.py :

python code.py 80

script :

python WebServer start

web.py "start" . , bacground.

-:

if __name__ == "__main__":
    if DEBUG:
        app.run()
    else:
        service = WebService(os.path.join(DIR_ACTUAL,'ElAdministrador.pid'))
        if len(sys.argv) == 2:
            if 'start' == sys.argv[1]:
                sys.argv[1] = '8080'
                service.start()
+5

web.py

/usr/bin/python index.py > log.txt 2>&1 & 
+4

, , . MyDaemon o.run(). , WebService -, -.

0

, :

if __name__ == "__main__":
    if DEBUG:
        app.run()
    else:
        service = WebService(os.path.join(DIR_ACTUAL,'ElAdministrador.pid'))
        if len(sys.argv) == 2:
            if 'start' == sys.argv[1]:
                sys.argv[1] = '8080'
                service.start()

'start | restart', :

if __name__ == "__main__":
    if DEBUG:
        app.run()
    else:
        service = WebService(os.path.join(DIR_ACTUAL,'ElAdministrador.pid'))
        if len(sys.argv) == 2:
            if 'start' == sys.argv[1]:
                delete del sys.argv[1:2]
                service.start()

, webpy , , . :

python WebServer start 8080
0

All Articles