def test_returns_none_when_file_nonexist(self):
     """ Should return None when the PID file does not exist. """
     set_pidlockfile_scenario(self, 'not-exist')
     pidfile_path = self.scenario['path']
     pid = pidlockfile.read_pid_from_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessIs(None, pid)
Example #2
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()
 def test_returns_none_when_file_nonexist(self):
     """ Should return None when the PID file does not exist. """
     set_pidlockfile_scenario(self, 'not-exist')
     pidfile_path = self.scenario['path']
     pid = pidlockfile.read_pid_from_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessIs(None, pid)
 def test_reads_pid_from_file(self):
     """ Should read the PID from the specified file. """
     set_pidlockfile_scenario(self, 'exist-other-pid')
     pidfile_path = self.scenario['path']
     expect_pid = self.scenario['pidfile_pid']
     pid = pidlockfile.read_pid_from_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessEqual(expect_pid, pid)
 def test_reads_pid_from_file(self):
     """ Should read the PID from the specified file. """
     set_pidlockfile_scenario(self, 'exist-other-pid')
     pidfile_path = self.scenario['path']
     expect_pid = self.scenario['pidfile_pid']
     pid = pidlockfile.read_pid_from_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessEqual(expect_pid, pid)
 def test_reads_pid_from_file(self):
     """ Should read the PID from the specified file. """
     set_pidlockfile_scenario(self, "exist-other-pid")
     pidfile_path = self.scenario["path"]
     expect_pid = self.scenario["pidfile_pid"]
     pid = pidlockfile.read_pid_from_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.assertEqual(expect_pid, pid)
 def test_opens_specified_filename(self):
     """ Should attempt to open specified pidfile filename. """
     set_pidlockfile_scenario(self, 'exist-other-pid')
     pidfile_path = self.scenario['path']
     expect_mock_output = """\
         Called __builtin__.open(%(pidfile_path)r, 'r')
         """ % vars()
     dummy = pidlockfile.read_pid_from_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessMockCheckerMatch(expect_mock_output)
 def test_opens_specified_filename(self):
     """ Should attempt to open specified pidfile filename. """
     set_pidlockfile_scenario(self, 'exist-other-pid')
     pidfile_path = self.scenario['path']
     expect_mock_output = u"""\
         Called builtins.open(%(pidfile_path)r, 'r')
         """ % vars()
     dummy = pidlockfile.read_pid_from_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessMockCheckerMatch(expect_mock_output)
Example #9
0
def stop_server():
    logging.info('Stopping server')

    pid = pidlockfile.read_pid_from_pidfile(PIDFILE)
    try:
        os.kill(pid, signal.SIGTERM)
    except OSError:
        logging.error('No such a process - cannot kill it')
    except TypeError:
        logging.error('Error reading pid file')
        
    pidlockfile.remove_existing_pidfile(PIDFILE)
Example #10
0
 def read_pid(self):
     return pidlockfile.read_pid_from_pidfile(self.path)