summaryrefslogtreecommitdiffstats
path: root/pyload
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-06-09 22:55:07 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-06-09 22:55:07 +0200
commit24b6d28baf559e151fc96ce2c15d17dfd78da479 (patch)
tree6dfc34734f3fc10a89ea66304795da4fb51fb7e2 /pyload
parentfixing imports when changing cwd (diff)
downloadpyload-24b6d28baf559e151fc96ce2c15d17dfd78da479.tar.xz
fixed start scripts
Diffstat (limited to 'pyload')
-rw-r--r--pyload/Core.py68
-rw-r--r--pyload/InitHomeDir.py5
2 files changed, 70 insertions, 3 deletions
diff --git a/pyload/Core.py b/pyload/Core.py
index 575eda357..16740bafa 100644
--- a/pyload/Core.py
+++ b/pyload/Core.py
@@ -5,19 +5,25 @@
# Copyright(c) 2008-2013 pyLoad Team
# http://www.pyload.org
#
-# This file is part of pyLoad.
-# pyLoad is free software: you can redistribute it and/or modify
+# 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
###############################################################################
CURRENT_VERSION = '0.4.9.9-dev'
import __builtin__
+
from getopt import getopt, GetoptError
import logging
import logging.handlers
@@ -601,3 +607,61 @@ class Core(object):
return join(pypath, *args)
+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() \ No newline at end of file
diff --git a/pyload/InitHomeDir.py b/pyload/InitHomeDir.py
index 3554497d3..c255913de 100644
--- a/pyload/InitHomeDir.py
+++ b/pyload/InitHomeDir.py
@@ -31,7 +31,10 @@ __builtin__.pypath = path.abspath(path.join(__file__, "..", ".."))
# Before changing the cwd, the abspath of the module must be manifested
if 'pyload' in sys.modules:
- sys.modules['pyload'].__path__.append(path.abspath(sys.modules['pyload'].__path__[0]))
+ rel_pyload = sys.modules['pyload'].__path__[0]
+ abs_pyload = path.abspath(rel_pyload)
+ if abs_pyload != rel_pyload:
+ sys.modules['pyload'].__path__.insert(0, abs_pyload)
sys.path.append(join(pypath, "pyload", "lib"))