#!/usr/bin/env python # -*- coding: utf-8 -*- ############################################################################### # Copyright(c) 2008-2013 pyLoad Team # http://www.pyload.org # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # Subjected to the terms and conditions in LICENSE # # @author: spoob # @author: sebnapi # @author: RaNaN # @author: mkaay # @version: v0.5.0 ############################################################################### import os import sys from os import _exit from pyload.Core import Core def deamon(): try: pid = os.fork() if pid > 0: sys.exit(0) except OSError, e: print >> sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror) sys.exit(1) # decouple from parent environment os.setsid() os.umask(0) # do second fork try: pid = os.fork() if pid > 0: # exit from second parent, print eventual PID before print "Daemon PID %d" % pid sys.exit(0) except OSError, e: print >> sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror) sys.exit(1) # Iterate through and close some file descriptors. for fd in range(0, 3): try: os.close(fd) except OSError: # ERROR, fd wasn't open to begin with (ignored) pass os.open(os.devnull, os.O_RDWR) # standard input (0) os.dup2(0, 1) # standard output (1) os.dup2(0, 2) pyload_core = Core() pyload_core.start() def main(): #change name to 'pyLoadCore' #from module.lib.rename_process import renameProcess #renameProcess('pyLoadCore') if "--daemon" in sys.argv: deamon() else: pyload_core = Core() try: pyload_core.start() except KeyboardInterrupt: pyload_core.shutdown() pyload_core.log.info(_("killed pyLoad from terminal")) pyload_core.removeLogger() _exit(1) # And so it begins... if __name__ == "__main__": main()