diff --git a/gertty/app.py b/gertty/app.py index 571327a..50c217c 100644 --- a/gertty/app.py +++ b/gertty/app.py @@ -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 = [] diff --git a/gertty/config.py b/gertty/config.py index dce9a6c..cf38b11 100644 --- a/gertty/config.py +++ b/gertty/config.py @@ -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),