public void start() { synchronized (lock) { if (state != State.DOWN) { log.debugf("Attempted to start already-running process '%s'", processName); return; } resetRespawnCount(); doStart(false); } }
@Override public void respawn(final int count, final ManagedProcess process, boolean slowRespawn, boolean unlimited) { if (unlimited || count <= MAX_RESTARTS) { try { final int[] waits = slowRespawn ? SLOW_WAITS : NORMAL_WAITS; int waitPeriod; if (count <= waits.length) { waitPeriod = waits[count - 1]; } else { waitPeriod = slowRespawn ? MAX_SLOW_WAIT : MAX_NORMAL_WAIT; } ProcessLogger.SERVER_LOGGER.waitingToRestart(waitPeriod, process.getProcessName()); TimeUnit.SECONDS.sleep(waitPeriod); } catch (InterruptedException e) { return; } process.respawn(); } } };
public void sendReconnectProcess(String processName, String scheme, String hostName, int port, boolean managementSubsystemEndpoint, String asAuthKey) { synchronized (lock) { ManagedProcess process = processes.get(processName); if (process == null) { ProcessLogger.ROOT_LOGGER.attemptToReconnectNonExistentProcess(processName); // ignore return; } process.reconnect(scheme, hostName, port, managementSubsystemEndpoint, asAuthKey); } }
void sendInventory() { synchronized (lock) { for (Connection connection : managedConnections) { try { final OutputStream os = connection.writeMessage(); try { os.write(Protocol.PROCESS_INVENTORY); final Collection<ManagedProcess> processCollection = processes.values(); StreamUtils.writeInt(os, processCollection.size()); for (ManagedProcess process : processCollection) { StreamUtils.writeUTFZBytes(os, process.getProcessName()); os.write(process.getAuthKey().getBytes(Charset.forName("US-ASCII"))); StreamUtils.writeBoolean(os, process.isRunning()); StreamUtils.writeBoolean(os, process.isStopping()); } os.close(); } finally { StreamUtils.safeClose(os); } } catch (IOException e) { ProcessLogger.ROOT_LOGGER.failedToWriteMessage("PROCESS_INVENTORY", e); removeManagedConnection(connection); } } } }
public void handleMessage(final Connection connection, final InputStream dataStream) throws IOException { final int cmd = readUnsignedByte(dataStream); if (cmd != Protocol.AUTH) { ProcessLogger.SERVER_LOGGER.receivedUnknownGreetingCode(Integer.valueOf(cmd), connection.getPeerAddress()); connection.close(); return; } final int version = StreamUtils.readUnsignedByte(dataStream); if (version < 1) { ProcessLogger.SERVER_LOGGER.receivedInvalidVersion(connection.getPeerAddress()); connection.close(); return; } final byte[] authCode = new byte[ProcessController.AUTH_BYTES_ENCODED_LENGTH]; StreamUtils.readFully(dataStream, authCode); final ManagedProcess process = processController.getServerByAuthCode(authCode); if (process == null) { ProcessLogger.SERVER_LOGGER.receivedUnknownCredentials(connection.getPeerAddress()); StreamUtils.safeClose(connection); return; } ProcessLogger.SERVER_LOGGER.tracef("Received authentic connection from %s", connection.getPeerAddress()); connection.setMessageHandler(new ConnectedMessageHandler(processController, process.isPrivileged())); processController.addManagedConnection(connection); dataStream.close(); // Reset the respawn count for the connecting process process.resetRespawnCount(); }
} else if (isPrivileged() && exitCode == ExitCodes.HOST_CONTROLLER_ABORT_EXIT_CODE) { respawnCount = ManagedProcess.this.incrementAndGetRespawnCount(); unlimitedRespawn = true; } else if (isPrivileged() && exitCode == ExitCodes.RESTART_PROCESS_FROM_STARTUP_SCRIPT) { if(! stopRequested) { respawn = true; respawnCount = ManagedProcess.this.incrementAndGetRespawnCount(); if (isPrivileged() && processController.getOngoingProcessCount() > 1) {
void respawn() { synchronized (lock) { if (state != State.DOWN) { log.debugf("Attempted to respawn already-running process '%s'", processName); return; } doStart(true); } }
@Override public void respawn(final int count, final ManagedProcess process, boolean slowRespawn, boolean unlimited) { ProcessLogger.SERVER_LOGGER.tracef("not trying to respawn process %s.", process.getProcessName()); }
public void removeProcess(final String processName) { synchronized (lock) { final Map<String, ManagedProcess> processes = this.processes; final ManagedProcess process = processes.get(processName); if (process == null) { ProcessLogger.ROOT_LOGGER.attemptToRemoveNonExistentProcess(processName); // ignore return; } boolean removed = processes.remove(processName) != null; processesByKey.remove(new Key(process.getAuthKey().getBytes(Charset.forName("US-ASCII")))); if(removed) { processRemoved(processName); } lock.notifyAll(); } }
public void addProcess(final String processName, int id, final String authKey, final List<String> command, final Map<String, String> env, final String workingDirectory, final boolean isPrivileged, final boolean respawn) { for (String s : command) { if (s == null) { throw ProcessLogger.ROOT_LOGGER.nullCommandComponent(); } } synchronized (lock) { if (shutdown) { return; } final Map<String, ManagedProcess> processes = this.processes; if (processes.containsKey(processName)) { ProcessLogger.ROOT_LOGGER.duplicateProcessName(processName); // ignore return; } final ManagedProcess process = new ManagedProcess(processName, id, command, env, workingDirectory, lock, this, authKey, isPrivileged, respawn); processes.put(processName, process); processesByKey.put(new Key(authKey.getBytes(Charset.forName("US-ASCII"))), process); processAdded(processName); } }
void sendInventory() { synchronized (lock) { for (Connection connection : managedConnections) { try { final OutputStream os = connection.writeMessage(); try { os.write(Protocol.PROCESS_INVENTORY); final Collection<ManagedProcess> processCollection = processes.values(); StreamUtils.writeInt(os, processCollection.size()); for (ManagedProcess process : processCollection) { StreamUtils.writeUTFZBytes(os, process.getProcessName()); os.write(process.getAuthKey().getBytes(Charset.forName("US-ASCII"))); StreamUtils.writeBoolean(os, process.isRunning()); StreamUtils.writeBoolean(os, process.isStopping()); } os.close(); } finally { StreamUtils.safeClose(os); } } catch (IOException e) { ProcessLogger.ROOT_LOGGER.failedToWriteMessage("PROCESS_INVENTORY", e); removeManagedConnection(connection); } } } }
public void handleMessage(final Connection connection, final InputStream dataStream) throws IOException { final int cmd = readUnsignedByte(dataStream); if (cmd != Protocol.AUTH) { ProcessLogger.SERVER_LOGGER.receivedUnknownGreetingCode(Integer.valueOf(cmd), connection.getPeerAddress()); connection.close(); return; } final int version = StreamUtils.readUnsignedByte(dataStream); if (version < 1) { ProcessLogger.SERVER_LOGGER.receivedInvalidVersion(connection.getPeerAddress()); connection.close(); return; } final byte[] authCode = new byte[ProcessController.AUTH_BYTES_ENCODED_LENGTH]; StreamUtils.readFully(dataStream, authCode); final ManagedProcess process = processController.getServerByAuthCode(authCode); if (process == null) { ProcessLogger.SERVER_LOGGER.receivedUnknownCredentials(connection.getPeerAddress()); StreamUtils.safeClose(connection); return; } ProcessLogger.SERVER_LOGGER.tracef("Received authentic connection from %s", connection.getPeerAddress()); connection.setMessageHandler(new ConnectedMessageHandler(processController, process.isPrivileged())); processController.addManagedConnection(connection); dataStream.close(); // Reset the respawn count for the connecting process process.resetRespawnCount(); }
} else if (isPrivileged() && exitCode == ExitCodes.HOST_CONTROLLER_ABORT_EXIT_CODE) { respawnCount = ManagedProcess.this.incrementAndGetRespawnCount(); unlimitedRespawn = true; } else if (isPrivileged() && exitCode == ExitCodes.RESTART_PROCESS_FROM_STARTUP_SCRIPT) { if(! stopRequested) { respawn = true; respawnCount = ManagedProcess.this.incrementAndGetRespawnCount(); if (isPrivileged() && processController.getOngoingProcessCount() > 1) {
void respawn() { synchronized (lock) { if (state != State.DOWN) { log.debugf("Attempted to respawn already-running process '%s'", processName); return; } doStart(true); } }
@Override public void respawn(final int count, final ManagedProcess process, boolean slowRespawn, boolean unlimited) { ProcessLogger.SERVER_LOGGER.tracef("not trying to respawn process %s.", process.getProcessName()); }
public void removeProcess(final String processName) { synchronized (lock) { final Map<String, ManagedProcess> processes = this.processes; final ManagedProcess process = processes.get(processName); if (process == null) { ProcessLogger.ROOT_LOGGER.attemptToRemoveNonExistentProcess(processName); // ignore return; } boolean removed = processes.remove(processName) != null; processesByKey.remove(new Key(process.getAuthKey().getBytes(Charset.forName("US-ASCII")))); if(removed) { processRemoved(processName); } lock.notifyAll(); } }
public void addProcess(final String processName, int id, final String authKey, final List<String> command, final Map<String, String> env, final String workingDirectory, final boolean isPrivileged, final boolean respawn) { for (String s : command) { if (s == null) { throw ProcessLogger.ROOT_LOGGER.nullCommandComponent(); } } synchronized (lock) { if (shutdown) { return; } final Map<String, ManagedProcess> processes = this.processes; if (processes.containsKey(processName)) { ProcessLogger.ROOT_LOGGER.duplicateProcessName(processName); // ignore return; } final ManagedProcess process = new ManagedProcess(processName, id, command, env, workingDirectory, lock, this, authKey, isPrivileged, respawn); processes.put(processName, process); processesByKey.put(new Key(authKey.getBytes(Charset.forName("US-ASCII"))), process); processAdded(processName); } }
void sendInventory() { synchronized (lock) { for (Connection connection : managedConnections) { try { final OutputStream os = connection.writeMessage(); try { os.write(Protocol.PROCESS_INVENTORY); final Collection<ManagedProcess> processCollection = processes.values(); StreamUtils.writeInt(os, processCollection.size()); for (ManagedProcess process : processCollection) { StreamUtils.writeUTFZBytes(os, process.getProcessName()); os.write(process.getAuthKey()); StreamUtils.writeBoolean(os, process.isRunning()); StreamUtils.writeBoolean(os, process.isStopping()); } os.close(); } finally { StreamUtils.safeClose(os); } } catch (IOException e) { ROOT_LOGGER.failedToWriteMessage("PROCESS_INVENTORY", e); removeManagedConnection(connection); } } } }