Skip to content

Commit

Permalink
initialize updater after daemonizing
Browse files Browse the repository at this point in the history
also some deamon tweaks
  • Loading branch information
N3MIS15 committed Sep 7, 2012
1 parent f92ef28 commit 83765a0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
9 changes: 5 additions & 4 deletions Maraschino.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def check_frozen():


def get_rundir(): def get_rundir():
if check_frozen(): 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 # Set the rundir
rundir = get_rundir() rundir = get_rundir()
Expand Down Expand Up @@ -176,11 +176,12 @@ def main():


maraschino.initialize() maraschino.initialize()


import_modules()

if maraschino.PIDFILE or maraschino.DAEMON: if maraschino.PIDFILE or maraschino.DAEMON:
maraschino.daemonize() maraschino.daemonize()


import_modules()
maraschino.init_updater()

maraschino.start() maraschino.start()




Expand Down
46 changes: 24 additions & 22 deletions maraschino/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
HOST = '0.0.0.0' HOST = '0.0.0.0'
KIOSK = False KIOSK = False
DATA_DIR = None DATA_DIR = None
THREADS = 0


AUTH = { AUTH = {
'username': None, 'username': None,
Expand All @@ -46,7 +47,7 @@ def initialize():
with INIT_LOCK: with INIT_LOCK:


global __INITIALIZED__, app, FULL_PATH, RUNDIR, ARGS, DAEMON, PIDFILE, VERBOSE, LOG_FILE, LOG_DIR, logger, PORT, SERVER, DATABASE, AUTH, \ 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__: if __INITIALIZED__:
return False return False
Expand Down Expand Up @@ -134,28 +135,29 @@ def initialize():
d = wsgiserver.WSGIPathInfoDispatcher({'/': app}) d = wsgiserver.WSGIPathInfoDispatcher({'/': app})
SERVER = wsgiserver.CherryPyWSGIServer((HOST, PORT), d) SERVER = wsgiserver.CherryPyWSGIServer((HOST, PORT), d)


# Set up the updater __INITIALIZED__ = True
from maraschino.updater import checkGithub, gitCurrentVersion 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 if os.name == 'nt':
return True 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(): def start_schedules():
Expand Down Expand Up @@ -234,6 +236,8 @@ def daemonize():
except OSError, e: except OSError, e:
sys.exit('1st fork failed: %s [%d]' % (e.strerror, e.errno)) sys.exit('1st fork failed: %s [%d]' % (e.strerror, e.errno))


os.chdir('/')
os.umask(0)
os.setsid() os.setsid()


try: try:
Expand All @@ -244,8 +248,6 @@ def daemonize():
except OSError, e: except OSError, e:
sys.exit('2nd fork failed: %s [%d]' % (e.strerror, e.errno)) sys.exit('2nd fork failed: %s [%d]' % (e.strerror, e.errno))


os.chdir('/')
os.umask(0)
pid = os.getpid() pid = os.getpid()


logger.log('Daemonized to PID: %s' % pid, 'INFO') logger.log('Daemonized to PID: %s' % pid, 'INFO')
Expand Down

0 comments on commit 83765a0

Please sign in to comment.