예제 #1
0
def start_server():
    logging.info('Server starting at: {0}'.format(datetime.now()))

    pid = None
    try:
        pid = pidlockfile.read_pid_from_pidfile(PIDFILE)
    except OSError:
        pass
    
    if pid is not None:
        try:
            os.getpgid(pid)
        except OSError:
            pidlockfile.remove_existing_pidfile(PIDFILE)
        else:
            init_application()
            return

    try:
        pidlockfile.write_pid_to_pidfile(PIDFILE)
    except OSError:
        logging.error('Pid file already exist, process must be running')
        sys.exit()
    
    init_application()
예제 #2
0
 def test_writes_pid_to_file(self):
     """ Should write the current PID to the specified file. """
     pidfile_path = self.scenario["path"]
     self.scenario["pidfile"].close = scaffold.Mock("PIDLockFile.close", tracker=self.mock_tracker)
     expect_line = "%(pid)d\n" % self.scenario
     pidlockfile.write_pid_to_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.assertEqual(expect_line, self.scenario["pidfile"].getvalue())
예제 #3
0
 def test_writes_pid_to_file(self):
     """ Should write the current PID to the specified file. """
     pidfile_path = self.scenario['path']
     self.scenario['pidfile'].close = scaffold.Mock(
         u"PIDLockFile.close", tracker=self.mock_tracker)
     expect_line = u"%(pid)d\n" % self.scenario
     pidlockfile.write_pid_to_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessEqual(expect_line, self.scenario['pidfile'].getvalue())
 def test_opens_specified_filename(self):
     """ Should attempt to open specified PID file filename. """
     pidfile_path = self.scenario['path']
     expect_flags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY)
     expect_mode = 0644
     expect_mock_output = """\
         Called os.open(%(pidfile_path)r, %(expect_flags)r, %(expect_mode)r)
         ...
         """ % vars()
     pidlockfile.write_pid_to_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessMockCheckerMatch(expect_mock_output)
예제 #5
0
 def test_opens_specified_filename(self):
     """ Should attempt to open specified PID file filename. """
     pidfile_path = self.scenario['path']
     expect_flags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY)
     expect_mode = 0644
     expect_mock_output = u"""\
         Called os.open(%(pidfile_path)r, %(expect_flags)r, %(expect_mode)r)
         ...
         """ % vars()
     pidlockfile.write_pid_to_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessMockCheckerMatch(expect_mock_output)
예제 #6
0
 def test_closes_file_after_write(self):
     """ Should close the specified file after writing. """
     pidfile_path = self.scenario['path']
     self.scenario['pidfile'].write = scaffold.Mock(
         u"PIDLockFile.write", tracker=self.mock_tracker)
     self.scenario['pidfile'].close = scaffold.Mock(
         u"PIDLockFile.close", tracker=self.mock_tracker)
     expect_mock_output = u"""\
         ...
         Called PIDLockFile.write(...)
         Called PIDLockFile.close()
         """ % vars()
     pidlockfile.write_pid_to_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessMockCheckerMatch(expect_mock_output)
예제 #7
0
 def test_closes_file_after_write(self):
     """ Should close the specified file after writing. """
     pidfile_path = self.scenario["path"]
     self.scenario["pidfile"].write = scaffold.Mock("PIDLockFile.write", tracker=self.mock_tracker)
     self.scenario["pidfile"].close = scaffold.Mock("PIDLockFile.close", tracker=self.mock_tracker)
     expect_mock_output = (
         """\
         ...
         Called PIDLockFile.write(...)
         Called PIDLockFile.close()
         """
         % vars()
     )
     pidlockfile.write_pid_to_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessMockCheckerMatch(expect_mock_output)
예제 #8
0
 def __enter__(self):
     try:
         pidlockfile.write_pid_to_pidfile(self.path)
     except OSError, exc:
         raise LockFailed(str(exc))