Compare commits

...

2 Commits

3 changed files with 25 additions and 4 deletions

View File

@ -5,6 +5,8 @@ import com.leakyabstractions.result.core.Results;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.lang.management.ManagementFactory;
import java.lang.ProcessHandle;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@ -140,8 +142,12 @@ public class LinuxScheduler {
throw new CronExpressionException("Message period not implemented: '" + settings.getMessagePeriod() + "'");
}
// TODO: figure out actual invocation
return scheduleString + " /home/nathanmcrae/personal_root/projects/numbers-station/run.sh --station \"" + settings.getName() + "\"";
String processName = ManagementFactory.getRuntimeMXBean().getName();
long pid = Long.parseLong(processName.split("@")[0]);
ProcessHandle currentProcess = ProcessHandle.of(pid).orElseThrow();
Path executablePath = currentProcess.info().command().map(Paths::get).orElseThrow();
logger.info("Executable Path: " + executablePath);
return scheduleString + " " + executablePath.toString() + " --station \"" + settings.getName() + "\"";
}
public static class CronExpressionException extends Exception {

View File

@ -115,6 +115,12 @@ public class Main extends Application {
public static void main(String[] args) {
MainParsedArguments parsedArgs = new MainParsedArguments(args);
if (parsedArgs.getParseException() != null) {
logger.log(Level.SEVERE, "Failed when parsing arguments", parsedArgs.getParseException());
parsedArgs.printHelp();
System.exit(0);
}
if (parsedArgs.getHelpFlag()) {
parsedArgs.printHelp();
System.exit(0);

View File

@ -7,8 +7,11 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.lang.ProcessHandle;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -215,13 +218,19 @@ public class WindowsScheduler {
Element exec = doc.createElement("Exec");
actions.appendChild(exec);
String processName = ManagementFactory.getRuntimeMXBean().getName();
long pid = Long.parseLong(processName.split("@")[0]);
ProcessHandle currentProcess = ProcessHandle.of(pid).orElseThrow();
Path executablePath = currentProcess.info().command().map(Paths::get).orElseThrow();
logger.info("Executable Path: " + executablePath);
Element command = doc.createElement("Command");
// TODO: need to figure out the real invocation
command.appendChild(doc.createTextNode("powershell"));
command.appendChild(doc.createTextNode(executablePath.toString()));
exec.appendChild(command);
Element arguments = doc.createElement("Arguments");
arguments.appendChild(doc.createTextNode("-Version 5 -NoProfile -File P:/personal_root/projects/numbers-station/run.ps1 --station \"" + station.getName() + "\""));
arguments.appendChild(doc.createTextNode("--station \"" + station.getName() + "\""));
exec.appendChild(arguments);
return doc;