use of org.apache.felix.utils.properties.Properties in project karaf by apache.
the class InstanceServiceImpl method cleanShutdown.
protected void cleanShutdown(InstanceState instance) {
try {
File file = new File(new File(instance.loc, "etc"), CONFIG_PROPERTIES_FILE_NAME);
Properties props = PropertiesLoader.loadPropertiesFile(file.toURI().toURL(), false);
props.put("karaf.base", new File(instance.loc).getCanonicalPath());
props.put("karaf.home", System.getProperty("karaf.home"));
props.put("karaf.data", new File(new File(instance.loc), "data").getCanonicalPath());
props.put("karaf.etc", new File(new File(instance.loc), "etc").getCanonicalPath());
InterpolationHelper.performSubstitution(props, null, true, false, true);
int port = Integer.parseInt(props.getProperty(KARAF_SHUTDOWN_PORT, "0"));
String host = props.getProperty(KARAF_SHUTDOWN_HOST, "localhost");
String portFile = props.getProperty(KARAF_SHUTDOWN_PORT_FILE);
String shutdown = props.getProperty(KARAF_SHUTDOWN_COMMAND, DEFAULT_SHUTDOWN_COMMAND);
if (port == 0 && portFile != null) {
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(portFile)));
String portStr = r.readLine();
port = Integer.parseInt(portStr);
r.close();
}
// We found the port, try to send the command
if (port > 0) {
Socket s = new Socket(host, port);
s.getOutputStream().write(shutdown.getBytes());
s.close();
long stopTimeout = Long.parseLong(props.getProperty(KARAF_SHUTDOWN_TIMEOUT, Long.toString(getStopTimeout())));
long t = System.currentTimeMillis() + stopTimeout;
do {
Thread.sleep(100);
checkPid(instance);
} while (System.currentTimeMillis() < t && instance.pid > 0);
}
} catch (Exception e) {
LOGGER.debug("Unable to cleanly shutdown instance " + instance.name, e);
}
}
use of org.apache.felix.utils.properties.Properties in project karaf by apache.
the class InstanceServiceImpl method loadPropertiesFile.
protected static Properties loadPropertiesFile(URL configPropURL) throws Exception {
try (InputStream is = configPropURL.openConnection().getInputStream()) {
Properties configProps = new Properties();
configProps.load(is);
return configProps;
} catch (Exception ex) {
System.err.println("Error loading config properties from " + configPropURL);
System.err.println("Main: " + ex);
return null;
}
}
use of org.apache.felix.utils.properties.Properties in project karaf by apache.
the class SystemServiceImpl method setSystemProperty.
@Override
public String setSystemProperty(String key, String value, boolean persist) {
if (persist) {
try {
String etc = System.getProperty("karaf.etc");
Properties props = new Properties(new File(etc, "system.properties"));
props.put(key, value);
props.save();
} catch (IOException e) {
throw new RuntimeException("Error persisting system property", e);
}
}
return System.setProperty(key, value);
}
use of org.apache.felix.utils.properties.Properties in project karaf by apache.
the class SystemServiceImpl method setFrameworkDebug.
public void setFrameworkDebug(boolean debug) {
try {
Properties properties = loadProps();
if (debug) {
properties.put("felix.log.level", "4");
properties.put("osgi.debug", "etc/equinox-debug.properties");
} else {
properties.remove("felix.log.level");
properties.remove("osgi.debug");
}
// TODO populate the equinox-debug.properties file with the one provided in shell/dev module
properties.save();
} catch (IOException e) {
throw new RuntimeException("Error setting framework debugging: " + e.getMessage(), e);
}
}
use of org.apache.felix.utils.properties.Properties in project karaf by apache.
the class SystemServiceImpl method setName.
@Override
public void setName(String name) {
try {
String karafEtc = bundleContext.getProperty("karaf.etc");
File etcDir = new File(karafEtc);
File syspropsFile = new File(etcDir, "system.properties");
FileInputStream fis = new FileInputStream(syspropsFile);
Properties props = new Properties();
props.load(fis);
fis.close();
props.setProperty("karaf.name", name);
FileOutputStream fos = new FileOutputStream(syspropsFile);
props.store(fos, "");
fos.close();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Aggregations