forked from I2P_Developers/i2p.i2p
Util: Consolidate linux service detection code
This commit is contained in:
@ -201,7 +201,7 @@ public class ConfigServiceHandler extends FormHandler {
|
||||
*/
|
||||
public boolean shouldShowSystray() {
|
||||
return !
|
||||
(RouterConsoleRunner.DAEMON_USER.equals(System.getProperty("user.name")) ||
|
||||
(SystemVersion.isLinuxService() ||
|
||||
(SystemVersion.isWindows() && _context.hasWrapper() && WrapperManager.isLaunchedAsService()) ||
|
||||
// headless=true is forced in i2prouter script to prevent useless dock icon;
|
||||
// must fix this first
|
||||
|
@ -131,7 +131,6 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
private static final int MAX_THREADS = 24;
|
||||
private static final int MAX_IDLE_TIME = 90*1000;
|
||||
private static final String THREAD_NAME = "RouterConsole Jetty";
|
||||
public static final String DAEMON_USER = "i2psvc";
|
||||
public static final String PROP_DTG_ENABLED = "desktopgui.enabled";
|
||||
|
||||
/**
|
||||
@ -273,7 +272,7 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
private void startTrayApp() {
|
||||
// if no permissions, don't even try
|
||||
// isLaunchedAsService() always returns true on Linux
|
||||
if (DAEMON_USER.equals(System.getProperty("user.name")) ||
|
||||
if (SystemVersion.isLinuxService() ||
|
||||
(SystemVersion.isWindows() && _context.hasWrapper() && WrapperManager.isLaunchedAsService())) {
|
||||
// required true for jrobin to work
|
||||
System.setProperty("java.awt.headless", "true");
|
||||
|
@ -16,6 +16,11 @@ import net.i2p.I2PAppContext;
|
||||
*/
|
||||
public abstract class SystemVersion {
|
||||
|
||||
/*
|
||||
* @since 0.9.28
|
||||
*/
|
||||
public static final String DAEMON_USER = "i2psvc";
|
||||
|
||||
private static final boolean _isWin = System.getProperty("os.name").startsWith("Win");
|
||||
private static final boolean _isMac = System.getProperty("os.name").startsWith("Mac");
|
||||
private static final boolean _isArm = System.getProperty("os.arch").startsWith("arm");
|
||||
@ -29,6 +34,8 @@ public abstract class SystemVersion {
|
||||
private static final boolean _isOpenJDK;
|
||||
private static final boolean _is64;
|
||||
private static final boolean _hasWrapper = System.getProperty("wrapper.version") != null;
|
||||
private static final boolean _isLinuxService = !_isWin && !_isMac &&
|
||||
DAEMON_USER.equals(System.getProperty("user.name"));
|
||||
|
||||
private static final boolean _oneDotSix;
|
||||
private static final boolean _oneDotSeven;
|
||||
@ -193,6 +200,13 @@ public abstract class SystemVersion {
|
||||
return _is64;
|
||||
}
|
||||
|
||||
/*
|
||||
* @since 0.9.28
|
||||
*/
|
||||
public static boolean isLinuxService() {
|
||||
return _isLinuxService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identical to android.os.Build.VERSION.SDK_INT.
|
||||
* For use outside of Android code.
|
||||
@ -268,6 +282,7 @@ public abstract class SystemVersion {
|
||||
System.out.println("Mac : " + isMac());
|
||||
System.out.println("Gentoo : " + isGentoo());
|
||||
System.out.println("GNU : " + isGNU());
|
||||
System.out.println("Linux Svc: " + isLinuxService());
|
||||
System.out.println("OpenJDK : " + isOpenJDK());
|
||||
System.out.println("Windows : " + isWindows());
|
||||
System.out.println("Wrapper : " + hasWrapper());
|
||||
|
@ -53,7 +53,6 @@ public class WorkingDir {
|
||||
private final static String WORKING_DIR_DEFAULT = ".i2p";
|
||||
private final static String WORKING_DIR_DEFAULT_DAEMON = "i2p-config";
|
||||
/** we do a couple of things differently if this is the username */
|
||||
private final static String DAEMON_USER = "i2psvc";
|
||||
private static final String PROP_WRAPPER_LOG = "wrapper.logfile";
|
||||
private static final String DEFAULT_WRAPPER_LOG = "wrapper.log";
|
||||
/** Feb 16 2006 */
|
||||
@ -93,7 +92,7 @@ public class WorkingDir {
|
||||
dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT_MAC);
|
||||
}
|
||||
} else {
|
||||
if (DAEMON_USER.equals(System.getProperty("user.name")))
|
||||
if (SystemVersion.isLinuxService())
|
||||
dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT_DAEMON);
|
||||
else
|
||||
dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT);
|
||||
@ -306,7 +305,7 @@ public class WorkingDir {
|
||||
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(newFile), "UTF-8")));
|
||||
out.println("# Modified by I2P User dir migration script");
|
||||
String s = null;
|
||||
boolean isDaemon = DAEMON_USER.equals(System.getProperty("user.name"));
|
||||
boolean isDaemon = SystemVersion.isLinuxService();
|
||||
while ((s = DataHelper.readLine(in)) != null) {
|
||||
// readLine() doesn't strip \r
|
||||
if (s.endsWith("\r"))
|
||||
|
@ -53,8 +53,7 @@ public class OOMListener implements I2PThread.OOMEventListener {
|
||||
// Can't find any System property or wrapper property that gives
|
||||
// you the actual config file path, have to guess
|
||||
String path;
|
||||
if (!SystemVersion.isWindows() && !SystemVersion.isMac() &&
|
||||
"i2psvc".equals(System.getProperty("user.name"))) {
|
||||
if (SystemVersion.isLinuxService()) {
|
||||
path = "/etc/i2p";
|
||||
} else {
|
||||
path = _context.getBaseDir().toString();
|
||||
|
@ -106,8 +106,7 @@ class BloomFilterIVValidator implements IVValidator {
|
||||
// you the actual config file path, have to guess
|
||||
// TODO if !SystemVersion.hasWrapper ...
|
||||
String path;
|
||||
if (!SystemVersion.isWindows() && !SystemVersion.isMac() &&
|
||||
"i2psvc".equals(System.getProperty("user.name"))) {
|
||||
if (SystemVersion.isLinuxService()) {
|
||||
path = "/etc/i2p";
|
||||
} else {
|
||||
path = _context.getBaseDir().toString();
|
||||
|
Reference in New Issue
Block a user