Merge "Prevent more than one gertty from running at a time"

This commit is contained in:
Jenkins 2016-07-26 17:23:39 +00:00 committed by Gerrit Code Review
commit 3addba09e7
2 changed files with 10 additions and 0 deletions

View File

@ -16,6 +16,7 @@
import argparse
import datetime
import dateutil
import fcntl
import functools
import logging
import os
@ -274,6 +275,13 @@ class App(object):
self.log = logging.getLogger('gertty.App')
self.log.debug("Starting")
self.lock_fd = open(self.config.lock_file, 'w')
try:
fcntl.lockf(self.lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
print("error: another instance of gertty is running for: %s" % self.config.server['name'])
sys.exit(1)
self.project_cache = ProjectCache()
self.ring = mywid.KillRing()
self.input_buffer = []

View File

@ -186,6 +186,8 @@ class Config(object):
self.socket_path = os.path.expanduser(socket_path)
log_file = server.get('log-file', '~/.gertty.log')
self.log_file = os.path.expanduser(log_file)
lock_file = server.get('lock-file', '~/.gertty.%s.lock' % server['name'])
self.lock_file = os.path.expanduser(lock_file)
self.palettes = {'default': gertty.palette.Palette({}),
'light': gertty.palette.Palette(gertty.palette.LIGHT_PALETTE),