我正在开发一个自动更新脚本,它应该能够在完成后重新启动守护进程。
我目前正在尝试这个:
final ArrayList<String> command = new ArrayList<String>();
String initScriptPath = Config.GetStringWithDefault("init_script", "/etc/init.d/my-daemon");
command.add("/bin/bash");
command.add("-c");
command.add("'" + initScriptPath + " restart'");
StringBuilder sb = new StringBuilder();
for (String c : command) {
sb.append(c).append(" ");
}
Log.write(LogPriority.DEBUG, "Attempting restart with: " + sb.toString());
final ProcessBuilder builder = new ProcessBuilder(command);
builder.start();
// Wait for a couple of seconds
try {
Thread.sleep(5000);
} catch (Exception e) {
}
System.exit(0);
但是 System.exit 似乎停止重新启动?它确实停止了,但不会重新开始。