-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lock file Optional when running logger #11
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,31 +36,40 @@ public class YoVariableLoggerDispatcher implements DataServerDiscoveryListener | |
private final YoVariableLoggerOptions options; | ||
|
||
/** | ||
* Create a new YovariableLoggerDispatcher. For every log that comes online, a YoVariableLogger is | ||
* Create a new YoVariableLoggerDispatcher. For every log that comes online, a YoVariableLogger is | ||
* created. | ||
* | ||
* @param options | ||
* @throws IOException | ||
*/ | ||
public YoVariableLoggerDispatcher(YoVariableLoggerOptions options) throws IOException | ||
{ | ||
if (lockFile.exists()) | ||
if (options.getDeployWithLockFile()) | ||
{ | ||
LogTools.info("Maybe if you weren't so full of yourself you would have checked if the logger was already running"); | ||
LogTools.info("Check the file: " + lockFile.getAbsolutePath() + " or run (ps aux | grep java)"); | ||
System.exit(0); | ||
} | ||
if (lockFile.exists()) | ||
{ | ||
LogTools.info("Maybe if you weren't so full of yourself you would have checked if the logger was already running"); | ||
LogTools.info("Check the file: " + lockFile.getAbsolutePath() + " or run (ps aux | grep java)"); | ||
System.exit(0); | ||
} | ||
|
||
lockFile.createNewFile(); | ||
Set<PosixFilePermission> perms = new HashSet<>(); | ||
if (!SystemUtils.OS_NAME.contains("Windows")) | ||
{ | ||
perms.add(PosixFilePermission.OWNER_READ); | ||
Files.setPosixFilePermissions(lockFile.toPath(), perms); | ||
} | ||
|
||
LogTools.info("Created Logger lock file"); | ||
|
||
lockFile.createNewFile(); | ||
Set<PosixFilePermission> perms = new HashSet<>(); | ||
if (!SystemUtils.OS_NAME.contains("Windows")) | ||
Runtime.getRuntime().addShutdownHook(new Thread(this::shutDownLockFile, "ShutdownThread")); | ||
} | ||
else | ||
{ | ||
perms.add(PosixFilePermission.OWNER_READ); | ||
Files.setPosixFilePermissions(lockFile.toPath(), perms); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoa whoa whoa, logger is starting without Lock File, be careful to make sure you only run one logger at a time. When redeploying as a service you should stop the service before deployment. Use ps aux | grep java to confirm. |
||
LogTools.info("Whoa whoa whoa, logger is starting without Lock File, be careful to make sure you only run one logger at a time"); | ||
} | ||
|
||
LogTools.info("Created Logger lock file"); | ||
|
||
this.options = options; | ||
LogTools.info("Starting YoVariableLoggerDispatcher"); | ||
|
||
|
@@ -70,16 +79,21 @@ public YoVariableLoggerDispatcher(YoVariableLoggerOptions options) throws IOExce | |
|
||
LogTools.info("Client started, waiting for data server sessions"); | ||
|
||
Runtime.getRuntime().addShutdownHook(new Thread(this::shutDownLockFile, "ShutdownThread")); | ||
|
||
ThreadTools.sleepForever(); | ||
} | ||
|
||
private void shutDownLockFile() | ||
{ | ||
lockFile.delete(); | ||
boolean shutdownProperly = lockFile.delete(); | ||
|
||
LogTools.info("Interrupted by Ctrl+C, deleting lock file"); | ||
if (!shutdownProperly) | ||
{ | ||
LogTools.error("Could not delete lock file: " + lockFile.getAbsolutePath()); | ||
} | ||
else | ||
{ | ||
LogTools.info("Interrupted by Ctrl+C, deleted lock file successfully"); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws JSAPException, IOException, InterruptedException | ||
|
@@ -106,7 +120,7 @@ public void connected(HTTPDataServerConnection connection) | |
{ | ||
try | ||
{ | ||
new YoVariableLogger(connection, options, (request) -> finishedLog(request)); | ||
new YoVariableLogger(connection, options, this::finishedLog); | ||
activeLogSessions.add(hashAnnouncement); | ||
LogTools.info("Logging session started for " + announcement.getNameAsString()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# /etc/cron.d/ihmc-logger-cron Restarts the ihmc-logger service nightly | ||
|
||
0 3 * * * root /bin/systemctl restart ihmc-logger | ||
0 3 * * * root /bin/systemctl restart ihmc-logger -l ${DEPLOY_WITH_LOCK_FILE} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be helpful to put "Lockfile found at (the path to the lockfile), This is likely from an existing logger running. Maybe if you weren't so full of yourself you would have checked if the logger was already running. If the logger is not running, it is safe to remove the file and restart the logger.