|
@ -4,6 +4,7 @@ import os |
|
|
import signal |
|
|
import signal |
|
|
import subprocess |
|
|
import subprocess |
|
|
import sys |
|
|
import sys |
|
|
|
|
|
import traceback |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Root path |
|
|
# Root path |
|
@ -50,39 +51,46 @@ class Loader(object): |
|
|
try: |
|
|
try: |
|
|
from couchpotato.runner import runCouchPotato |
|
|
from couchpotato.runner import runCouchPotato |
|
|
runCouchPotato(self.options, base_path, sys.argv[1:]) |
|
|
runCouchPotato(self.options, base_path, sys.argv[1:]) |
|
|
except KeyboardInterrupt: |
|
|
except (KeyboardInterrupt, SystemExit): |
|
|
pass |
|
|
pass |
|
|
except Exception, e: |
|
|
except: |
|
|
self.log.critical(e) |
|
|
self.log.error(traceback.format_exc()) |
|
|
|
|
|
|
|
|
if self.do_restart: |
|
|
if self.do_restart: |
|
|
self.restart() |
|
|
self.restart() |
|
|
|
|
|
|
|
|
sys.exit(0) |
|
|
|
|
|
|
|
|
|
|
|
def restart(self): |
|
|
def restart(self): |
|
|
try: |
|
|
try: |
|
|
# remove old pidfile first |
|
|
# remove old pidfile first |
|
|
if self.runAsDaemon(): |
|
|
try: |
|
|
self.daemon.delpid() |
|
|
if self.runAsDaemon(): |
|
|
|
|
|
self.daemon.delpid() |
|
|
|
|
|
except: |
|
|
|
|
|
self.log.error(traceback.format_exc()) |
|
|
|
|
|
|
|
|
args = [sys.executable] + [os.path.join(base_path, __file__)] + sys.argv[1:] |
|
|
args = [sys.executable] + [os.path.join(base_path, __file__)] + sys.argv[1:] |
|
|
subprocess.Popen(args) |
|
|
subprocess.Popen(args) |
|
|
except Exception, e: |
|
|
except: |
|
|
self.log.critical(e) |
|
|
self.log.error(traceback.format_exc()) |
|
|
return 0 |
|
|
|
|
|
|
|
|
|
|
|
def daemonize(self): |
|
|
def daemonize(self): |
|
|
|
|
|
|
|
|
if self.runAsDaemon(): |
|
|
if self.runAsDaemon(): |
|
|
from daemon import Daemon |
|
|
try: |
|
|
self.daemon = Daemon(self.options.pid_file) |
|
|
from daemon import Daemon |
|
|
self.daemon.daemonize() |
|
|
self.daemon = Daemon(self.options.pid_file) |
|
|
|
|
|
self.daemon.daemonize() |
|
|
|
|
|
except: |
|
|
|
|
|
self.log.error(traceback.format_exc()) |
|
|
|
|
|
|
|
|
def runAsDaemon(self): |
|
|
def runAsDaemon(self): |
|
|
return self.options.daemon and self.options.pid_file |
|
|
return self.options.daemon and self.options.pid_file |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
l = Loader() |
|
|
try: |
|
|
l.daemonize() |
|
|
l = Loader() |
|
|
l.run() |
|
|
l.daemonize() |
|
|
|
|
|
l.run() |
|
|
|
|
|
except: |
|
|
|
|
|
pass |
|
|