-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripts class and shutdown operations
- Loading branch information
Michael Pozhidaev
committed
Mar 14, 2016
1 parent
7b7a071
commit c03b312
Showing
4 changed files
with
45 additions
and
12 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash -e | ||
|
||
/sbin/reboot | ||
/sbin/reboot --force |
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 @@ | ||
#!/bin/bash -e | ||
|
||
/sbin/poweroff | ||
/sbin/poweroff --force |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
package org.luwrain.linux; | ||
|
||
import java.nio.file.*; | ||
import java.io.*; | ||
import org.luwrain.core.*; | ||
|
||
class Scripts | ||
{ | ||
private Path scriptsDir; | ||
|
||
Scripts(Path scriptsDir) | ||
{ | ||
NullCheck.notNull(scriptsDir, "scriptsDir"); | ||
this.scriptsDir = scriptsDir; | ||
} | ||
|
||
boolean runSync(String scriptName, boolean sudo) | ||
{ | ||
try { | ||
final Process p = sudo?new ProcessBuilder("sudo", scriptsDir.resolve(scriptName).toString()).start(): | ||
new ProcessBuilder(scriptsDir.resolve(scriptName).toString()).start(); | ||
p.getOutputStream().close(); | ||
p.waitFor(); | ||
return p.exitValue() == 0; | ||
} | ||
catch(InterruptedException e) | ||
{ | ||
Thread.currentThread().interrupt(); | ||
return false; | ||
} | ||
catch(IOException e) | ||
{ | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
} | ||
} |