Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfboys committed Aug 31, 2018
1 parent 4da793c commit 3ad66cd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ public static int execute(final String user, final File file, final String comma

public static String buildCommand(final String proxyUser, final File execFile, final String command) {
AssertUtils.notNull(command);
//写入命令到文件
write(execFile, command);

if (CommonUtils.isWindows()) {
return String.format("call %s",execFile.getAbsolutePath());
return command;
}

//写入命令到文件
write(execFile, command);

String execCmd = String.format("/bin/bash +x %s", execFile.getAbsolutePath());
if ( CommonUtils.notEmpty(proxyUser)) {
//授权文件...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,16 @@ private Integer getProcessId() {
if (this.process == null) return null;
if (CommonUtils.isUnix()) {
Field field = ReflectUtils.getField(this.process.getClass(), "pid");
return field.getInt(this.process);
if (field!=null) {
return field.getInt(this.process);
}
}else if(CommonUtils.isWindows()) {
Field field = ReflectUtils.getField(this.process.getClass(), "handle");
WinNT.HANDLE handle = new WinNT.HANDLE();
long handl = field.getLong(this.process);
handle.setPointer(Pointer.createConstant(handl));
return Kernel32.INSTANCE.GetProcessId(handle);
if (field!=null) {
WinNT.HANDLE handle = new WinNT.HANDLE();
handle.setPointer(Pointer.createConstant(field.getLong(this.process)));
return Kernel32.INSTANCE.GetProcessId(handle);
}
}
}catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -343,7 +346,10 @@ private Logger getLogger(String name) {
}

private File getExecShell(String pid) {
return new File(String.format("%s/.%s.%s",Constants.JOBX_TMP_PATH,pid,CommonUtils.isWindows()?"bat":"sh"));
if (CommonUtils.isUnix()) {
return new File(String.format("%s/.%s.%s",Constants.JOBX_TMP_PATH,pid,"sh"));
}
return null;
}

private File getLogFile(String pid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public abstract class CommandUtils implements Serializable {

public static String BASH_SCHEAM = "#!/bin/bash";

public static String BAT_SCHEAM = "@echo off";

public static File createShellFile(String command, String shellFileName) {
String dirPath = IOUtils.getTmpdir();
File dir = new File(dirPath);
Expand Down Expand Up @@ -273,7 +271,7 @@ public static void write(File shellFile, String command) {
try {
if (!shellFile.exists()) {
PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(shellFile)));
out.write(CommonUtils.isWindows()?BAT_SCHEAM:BASH_SCHEAM);
out.write(BASH_SCHEAM);
out.write("\n\r\n\r");
out.write(command);
out.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public List<String> getRecentTriggerTime(String cronExp) {
public Map<String,Integer> validatePing(Agent agent) {
Map<String,Integer> result = new HashMap<String, Integer>(0);
if (hasProxy(agent, result)) return result;
Constants.ConnStatus connStatus = executeService.ping(agent,false);
Constants.ConnStatus connStatus = executeService.ping(agent,true);
result.put("status",connStatus.getValue());
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ public void initialize() {
List<Agent> agentList = this.agentService.getAll();
if (CommonUtils.notEmpty(agentList)) {
for (Agent agent : agentList) {
if(agent.getStatus() == Constants.ConnStatus.DISCONNECTED.getValue()) {
executeService.ping(agent,true);
}
executeService.ping(agent,true);
}
}

Expand Down

0 comments on commit 3ad66cd

Please sign in to comment.