Class ServiceWrapper
StartService with its defects fixed): installed by bin\ntservice\is.bat as the process SrvAny runs, it starts the server and supervises it with the exit-code contract of com.iizix.server.ServerExit as Windows reads it, the same as iiziServer.bat:- 0, 8, 9: no relaunch, the wrapper exits with the server's code (SrvAny reports it);
- 100: relaunch at once;
- 101: the updater first (
ServerUpdater, from this very jar: the updater copies it to a temporary file itself), honouring its exit code - 0 updated, 1 refused or rolled back (the previous version is relaunched and the log says so), 2 or more the rollback failed: the wrapper exits 1 and the installation needs the operator; - anything else, a crash, and 1 as well: on Windows a JVM crash (hs_err), an uncaught
OutOfMemoryErrorand a kill (TerminateProcess, Task Manager's End task) all end the process with 1, which on POSIX is the code of a fatal error (measured on JDK 8 to 26, CC-NP-UPGRADE-FOLLOWUP NP-F-1; CC-FIX-WRAPPER-RELAUNCH): a relaunch after 10000L ms, at most 5 times within 300000L ms, then the wrapper exits with the last code (SrvAny reports a clean stop whatever the code, so the Windows recovery never triggers: the back-off is here, D-7).
ServerUpdater -rollback, which does nothing without its marker).The graceful stop (stage-native of the order): the new SrvAny writes the file "service.stop" into the installation on a service STOP and waits; the wrapper sees it, writes "server.stop", which the server watches (ServiceStopWatcher) and answers with its own stop (exit 0 through its dispose), and does not relaunch; a server that has not ended within 90000L ms is destroyed. The old SrvAny kills the tree instead: nothing here runs then, and nothing needs to.
The output. The server's standard output and error go to logs/iiziServer-console.log through ProcessBuilder's redirection (no reader threads); the wrapper's own timestamped lines - start, restart, update, stop, crash - go to logs/iiziServerWrapper.log and, when the event log is on, to the NT Event Log through setEventLogger(BiConsumer). Both files are rotated at 20000000L bytes.
Usage: ServiceWrapper [-install <dir>] [-ntEventLog off|on|info] [-ntEventSource <name>] <javaExe> <java options...> <mainClass> [<args...>] - everything from the Java executable on is the server's command line, to which the wrapper adds -supervisor wrapper and, ONLY when given, the two event-log options. Test options: -updaterClass <class>, -crashBackoffMs <n>, -crashWindowMs <n>, -updaterClassPath <path>.
Nothing here depends on another IIZI class: the wrapper runs from the tools jar, before the server.
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe logs.static final longThe back-off after a crash, in milliseconds (10 s, D-7).static final intThe relaunches after crashes withinCRASH_WINDOW_MSbefore the wrapper gives up (5).static final longThe window ofCRASH_RELAUNCHES, in milliseconds (300 s).static final intThe event classes of the NT Event Log (the DLL's): error, warning, informational.static final intThe event classes of the NT Event Log (the DLL's): error, warning, informational.static final intThe event classes of the NT Event Log (the DLL's): error, warning, informational.static final longThe size at which a log is rotated to.1.static final StringThe file the wrapper writes for the server, which watches it and stops.static final StringThe file SrvAny writes into the installation on a service STOP.static final longHow long a server may take to stop after the stop file, before it is destroyed.static final StringThe logs.Method Summary
Modifier and TypeMethodDescriptionstatic voidThe entry: the wrapper's exit code is the server's.static intrun(String[] args, PrintStream out) Runs the wrapper and returns its exit code (the test's entry).static voidsetEventLogger(BiConsumer<Integer, String> logger) Sets the event logger: what receives the wrapper's own lines besides its log file.
Field Details
CRASH_BACKOFF_MS
public static final long CRASH_BACKOFF_MSThe back-off after a crash, in milliseconds (10 s, D-7).- See Also:
CRASH_RELAUNCHES
public static final int CRASH_RELAUNCHESThe relaunches after crashes withinCRASH_WINDOW_MSbefore the wrapper gives up (5).- See Also:
CRASH_WINDOW_MS
public static final long CRASH_WINDOW_MSThe window ofCRASH_RELAUNCHES, in milliseconds (300 s).- See Also:
STOP_TIMEOUT_MS
public static final long STOP_TIMEOUT_MSHow long a server may take to stop after the stop file, before it is destroyed.- See Also:
SERVICE_STOP
The file SrvAny writes into the installation on a service STOP.- See Also:
SERVER_STOP
The file the wrapper writes for the server, which watches it and stops.- See Also:
WRAPPER_LOG
CONSOLE_LOG
ROTATE_BYTES
public static final long ROTATE_BYTESThe size at which a log is rotated to.1.- See Also:
EVENT_ERROR
public static final int EVENT_ERRORThe event classes of the NT Event Log (the DLL's): error, warning, informational.- See Also:
EVENT_WARNING
public static final int EVENT_WARNINGThe event classes of the NT Event Log (the DLL's): error, warning, informational.- See Also:
EVENT_INFORMATIONAL
public static final int EVENT_INFORMATIONALThe event classes of the NT Event Log (the DLL's): error, warning, informational.- See Also:
Method Details
setEventLogger
Sets the event logger: what receives the wrapper's own lines besides its log file.- Parameters:
logger- The logger (event class, message), null for none.
main
The entry: the wrapper's exit code is the server's.- Parameters:
args- The options, then the server's command line.
run
Runs the wrapper and returns its exit code (the test's entry).- Parameters:
args- The options, then the server's command line.out- The standard output.- Returns:
- The exit code.