|
@@ -44,42 +44,7 @@ helpers.initialize_gettext()
|
|
|
helpers.setup_sighandler()
|
|
|
PARSER = helpers.parse_arguments()
|
|
|
ARGUMENTS = PARSER.parse_args()
|
|
|
-
|
|
|
-# Create the lock file which is used to determine if another instance is
|
|
|
-# already running by chance, the program shouldn't be run in this case since
|
|
|
-# we want to prevent concurent access to the database.
|
|
|
-
|
|
|
-if os.access("/tmp/stov.lock", os.F_OK):
|
|
|
- try:
|
|
|
- LOCK_FILE = open("/tmp/stov.lock", "r")
|
|
|
- except IOError:
|
|
|
- print(_("The lock file could not be opened, please check that "
|
|
|
- "it exists and is readable, quitting now"),
|
|
|
- file=sys.stderr)
|
|
|
- sys.exit(1)
|
|
|
- OLD_PID = LOCK_FILE.read().strip()
|
|
|
- if os.access("/proc/" + OLD_PID, os.F_OK):
|
|
|
- print(_("The lock file already exists, probably another "
|
|
|
- "instance of this program is already running\n"
|
|
|
- "if you are sure this is not the case, delete it"
|
|
|
- " manually and try again!"), file=sys.stderr)
|
|
|
- sys.exit(1)
|
|
|
- LOCK_FILE.close()
|
|
|
- if os.access("/proc/" + OLD_PID, os.F_OK) is not True:
|
|
|
- try:
|
|
|
- os.remove("/tmp/stov.lock")
|
|
|
- except os.error:
|
|
|
- print(_("The old lock file could not be deleted!"),
|
|
|
- file=sys.stderr)
|
|
|
-try:
|
|
|
- LOCK_FILE = open("/tmp/stov.lock", "w")
|
|
|
- LOCK_FILE.write(str(os.getpid()))
|
|
|
- LOCK_FILE.close()
|
|
|
-except IOError:
|
|
|
- print(_("The lock file could not be created, please check that /tmp"
|
|
|
- " is writable and properly configured, quitting now."),
|
|
|
- file=sys.stderr)
|
|
|
- sys.exit(1)
|
|
|
+helpers.create_lock()
|
|
|
|
|
|
# Check if the configuration directory exists and is writeable. If it
|
|
|
# doesnt, create it using the configuration class.
|
|
@@ -533,12 +498,5 @@ elif ARGUMENTS.version is True:
|
|
|
else:
|
|
|
PARSER.print_help()
|
|
|
|
|
|
-# Remove the lock file and end the program so it can be run again
|
|
|
|
|
|
-try:
|
|
|
- os.remove("/tmp/stov.lock")
|
|
|
- sys.exit(0)
|
|
|
-except os.error:
|
|
|
- LOGGER.error(_("Could not delete the lock file. Please check what "
|
|
|
- "went wrong and clean up manually!"))
|
|
|
- sys.exit(1)
|
|
|
+helpers.remove_lock()
|