Browse files

initialize updater after daemonizing

also some deamon tweaks
  • Loading branch information...
1 parent f92ef28 commit 83765a0dd9445d4f9e9acfc101aae406b003d5db @N3MIS15 N3MIS15 committed Sep 8, 2012
Showing with 29 additions and 26 deletions.
  1. +5 −4 Maraschino.py
  2. +24 −22 maraschino/__init__.py
View
9 Maraschino.py
@@ -13,9 +13,9 @@ def check_frozen():
def get_rundir():
if check_frozen():
- return os.path.dirname(unicode(sys.executable, sys.getfilesystemencoding( )))
+ return os.path.abspath(unicode(sys.executable, sys.getfilesystemencoding( )))
- return os.path.dirname(unicode(__file__, sys.getfilesystemencoding( )))
+ return os.path.abspath(__file__)[:-13]
# Set the rundir
rundir = get_rundir()
@@ -176,11 +176,12 @@ def main():
maraschino.initialize()
- import_modules()
-
if maraschino.PIDFILE or maraschino.DAEMON:
maraschino.daemonize()
+ import_modules()
+ maraschino.init_updater()
+
maraschino.start()
View
46 maraschino/__init__.py
@@ -29,6 +29,7 @@
HOST = '0.0.0.0'
KIOSK = False
DATA_DIR = None
+THREADS = 0
AUTH = {
'username': None,
@@ -46,7 +47,7 @@ def initialize():
with INIT_LOCK:
global __INITIALIZED__, app, FULL_PATH, RUNDIR, ARGS, DAEMON, PIDFILE, VERBOSE, LOG_FILE, LOG_DIR, logger, PORT, SERVER, DATABASE, AUTH, \
- CURRENT_COMMIT, LATEST_COMMIT, COMMITS_BEHIND, COMMITS_COMPARE_URL, USE_GIT, WEBROOT, HOST, KIOSK, DATA_DIR
+ CURRENT_COMMIT, LATEST_COMMIT, COMMITS_BEHIND, COMMITS_COMPARE_URL, USE_GIT, WEBROOT, HOST, KIOSK, DATA_DIR, THREADS
if __INITIALIZED__:
return False
@@ -134,28 +135,29 @@ def initialize():
d = wsgiserver.WSGIPathInfoDispatcher({'/': app})
SERVER = wsgiserver.CherryPyWSGIServer((HOST, PORT), d)
- # Set up the updater
- from maraschino.updater import checkGithub, gitCurrentVersion
+ __INITIALIZED__ = True
+ return True
- if os.name == 'nt':
- USE_GIT = False
- else:
- USE_GIT = os.path.isdir(os.path.join(RUNDIR, '.git'))
- if USE_GIT:
- gitCurrentVersion()
-
- version_file = os.path.join(DATA_DIR, 'Version.txt')
- if os.path.isfile(version_file):
- f = open(version_file, 'r')
- CURRENT_COMMIT = f.read()
- f.close()
- else:
- COMMITS_BEHIND = -1
- threading.Thread(target=checkGithub).start()
+def init_updater():
+ from maraschino.updater import checkGithub, gitCurrentVersion
- __INITIALIZED__ = True
- return True
+ if os.name == 'nt':
+ USE_GIT = False
+ else:
+ USE_GIT = os.path.isdir(os.path.join(RUNDIR, '.git'))
+ if USE_GIT:
+ gitCurrentVersion()
+
+ version_file = os.path.join(DATA_DIR, 'Version.txt')
+ if os.path.isfile(version_file):
+ f = open(version_file, 'r')
+ CURRENT_COMMIT = f.read()
+ f.close()
+ else:
+ COMMITS_BEHIND = -1
+
+ threading.Thread(target=checkGithub).start()
def start_schedules():
@@ -234,6 +236,8 @@ def daemonize():
except OSError, e:
sys.exit('1st fork failed: %s [%d]' % (e.strerror, e.errno))
+ os.chdir('/')
+ os.umask(0)
os.setsid()
try:
@@ -244,8 +248,6 @@ def daemonize():
except OSError, e:
sys.exit('2nd fork failed: %s [%d]' % (e.strerror, e.errno))
- os.chdir('/')
- os.umask(0)
pid = os.getpid()
logger.log('Daemonized to PID: %s' % pid, 'INFO')

0 comments on commit 83765a0

Please sign in to comment.