示例#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()
 def test_removes_specified_filename(self):
     """ Should attempt to remove specified PID file filename. """
     set_pidlockfile_scenario(self, 'exist-current-pid')
     pidfile_path = self.scenario['path']
     expect_mock_output = """\
         Called os.remove(%(pidfile_path)r)
         """ % vars()
     pidlockfile.remove_existing_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessMockCheckerMatch(expect_mock_output)
示例#3
0
 def test_removes_specified_filename(self):
     """ Should attempt to remove specified PID file filename. """
     set_pidlockfile_scenario(self, 'exist-current-pid')
     pidfile_path = self.scenario['path']
     expect_mock_output = u"""\
         Called os.remove(%(pidfile_path)r)
         """ % vars()
     pidlockfile.remove_existing_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessMockCheckerMatch(expect_mock_output)
 def test_ignores_file_not_exist_error(self):
     """ Should ignore error if file does not exist. """
     set_pidlockfile_scenario(self, 'not-exist')
     pidfile_path = self.scenario['path']
     mock_error = OSError(errno.ENOENT, "Not there", pidfile_path)
     os.remove.mock_raises = mock_error
     expect_mock_output = """\
         Called os.remove(%(pidfile_path)r)
         """ % vars()
     pidlockfile.remove_existing_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessMockCheckerMatch(expect_mock_output)
示例#5
0
 def test_ignores_file_not_exist_error(self):
     """ Should ignore error if file does not exist. """
     set_pidlockfile_scenario(self, 'not-exist')
     pidfile_path = self.scenario['path']
     mock_error = OSError(errno.ENOENT, u"Not there", pidfile_path)
     os.remove.mock_raises = mock_error
     expect_mock_output = u"""\
         Called os.remove(%(pidfile_path)r)
         """ % vars()
     pidlockfile.remove_existing_pidfile(pidfile_path)
     scaffold.mock_restore()
     self.failUnlessMockCheckerMatch(expect_mock_output)
示例#6
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)