mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Simplify lock file scanning in stop command.
This simpler implementation only requires that a lock file begin with the stanza (followed by a dash) and end in .lock. This will make the implementation more resilient to planned changes in lock file naming.
This commit is contained in:
parent
ea1596152c
commit
48823b6cd3
@ -45,6 +45,8 @@ cmdStop(void)
|
||||
if (cfgOptionBool(cfgOptForce))
|
||||
{
|
||||
const String *const lockPath = cfgOptionStr(cfgOptLockPath);
|
||||
const String *const stanzaPrefix =
|
||||
cfgOptionTest(cfgOptStanza) ? strNewFmt("%s-", strZ(cfgOptionStr(cfgOptStanza))) : NULL;
|
||||
const StringList *const lockPathFileList = strLstSort(
|
||||
storageListP(storageLocal(), lockPath, .errorOnMissing = true), sortOrderAsc);
|
||||
|
||||
@ -54,30 +56,25 @@ cmdStop(void)
|
||||
const String *lockFile = strLstGet(lockPathFileList, lockPathFileIdx);
|
||||
|
||||
// Skip any file that is not a lock file. Skip lock files for other stanzas if a stanza is provided.
|
||||
if (!strEndsWithZ(lockFile, LOCK_FILE_EXT) ||
|
||||
(cfgOptionTest(cfgOptStanza) &&
|
||||
!strEq(lockFile, lockFileName(cfgOptionStr(cfgOptStanza), lockTypeArchive)) &&
|
||||
!strEq(lockFile, lockFileName(cfgOptionStr(cfgOptStanza), lockTypeBackup))))
|
||||
{
|
||||
if (!strEndsWithZ(lockFile, LOCK_FILE_EXT) || (stanzaPrefix != NULL && !strBeginsWith(lockFile, stanzaPrefix)))
|
||||
continue;
|
||||
}
|
||||
|
||||
// Read the lock file
|
||||
lockFile = strNewFmt("%s/%s", strZ(lockPath), strZ(lockFile));
|
||||
const LockReadResult lockRead = lockReadFileP(lockFile, .remove = true);
|
||||
const LockReadResult lockResult = lockReadFileP(lockFile, .remove = true);
|
||||
|
||||
// If we cannot read the lock file for any reason then warn and continue to next file
|
||||
if (lockRead.status != lockReadStatusValid)
|
||||
if (lockResult.status != lockReadStatusValid)
|
||||
{
|
||||
LOG_WARN_FMT("unable to read lock file %s", strZ(lockFile));
|
||||
continue;
|
||||
}
|
||||
|
||||
// The lock file is valid so that means there is a running process -- send a term signal to the process
|
||||
if (kill(lockRead.data.processId, SIGTERM) != 0)
|
||||
LOG_WARN_FMT("unable to send term signal to process %d", lockRead.data.processId);
|
||||
if (kill(lockResult.data.processId, SIGTERM) != 0)
|
||||
LOG_WARN_FMT("unable to send term signal to process %d", lockResult.data.processId);
|
||||
else
|
||||
LOG_INFO_FMT("sent term signal to process %d", lockRead.data.processId);
|
||||
LOG_INFO_FMT("sent term signal to process %d", lockResult.data.processId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user