Vfs.setPwd(_args.getRootDirectory());
boolean isLogDirectoryExists = getLogDirectory().exists();
Path logPath = getLogDirectory().lookup("watchdog-manager.log");
try {
getLogDirectory().mkdirs();
} catch (Exception e) {
log().log(Level.ALL, e.toString(), e);
}
// #4333 - check watchdog-manager.log can be written
WriteStream testOut = logPath.openAppend();
testOut.close();
if (! logPath.canWrite()) {
throw new ConfigException("Cannot open " + logPath.getNativePath()
+ " required for Resin start. Please check permissions");
}
RotateStream logStream = RotateStream.create(logPath);
logStream.setRolloverSize(64L * 1024 * 1024);
logStream.init();
WriteStream out = logStream.getStream();
out.setDisableClose(true);
EnvironmentStream.setStdout(out);
EnvironmentStream.setStderr(out);
LogHandlerConfig log = new LogHandlerConfig();
log.setName("");
log.setPath(logPath);
log.init();
Thread thread = Thread.currentThread();
thread.setContextClassLoader(_system.getClassLoader());
ThreadPool.getThreadPool().setIdleMin(4);
ThreadPool.getThreadPool().setPriorityIdleMin(4);
ResinELContext elContext = _args.getELContext();
Resin resin = Resin.createWatchdog(_system);
if (_args.getDataDirectory() != null)
resin.setDataDirectory(_args.getDataDirectory());
resin.preConfigureInit();
// XXX: needs to be config
InjectManager cdiManager = InjectManager.create();
Config.setProperty("resinHome", elContext.getResinHome());
Config.setProperty("resin", elContext.getResinVar());
Config.setProperty("server", elContext.getServerVar());
Config.setProperty("java", elContext.getJavaVar());
Config.setProperty("system", System.getProperties());
Config.setProperty("getenv", System.getenv());
ResinConfigLibrary.configure(cdiManager);
_watchdogPort = _args.getWatchdogPort();
readConfig(_args);
WatchdogChild server = null;
String serverId = _args.getServerId();
if (_args.isDynamicServer()) {
serverId = _args.getDynamicServerId();
}
server = _watchdogMap.get(_args.getServerId());
if (server == null)
throw new IllegalStateException(L().l("'{0}' is an unknown server",
serverId));
JniBoot boot = new JniBoot();
Path logDirectory = getLogDirectory();
if (boot.isValid()) {
if (! isLogDirectoryExists) {
logDirectory.mkdirs();
boot.chown(logDirectory, server.getUserName(), server.getGroupName());
}
}