Prevent more than one gertty from running at a time

Currently it results in a corrupted db, so prevent that from happening.

Change-Id: I42386214cbe62cb127db68269f377f3d7575425e
This commit is contained in:
Doug Wiegley 2016-06-10 21:28:59 -06:00
parent 27f90d0b73
commit 8c74f9964f
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),