Class ConfigureWindowsService
- java.lang.Object
-
- com.forgerock.opendj.cli.Tool
-
- org.opends.server.tools.ConfigureWindowsService
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public final class ConfigureWindowsService extends com.forgerock.opendj.cli.Tool
This class is used to configure the Windows service for this instance on this machine. This tool allows to enable and disable OpenDJ to run as a Windows service and allows to know if OpenDJ is running as a Windows service or not.Some comments about Vista: In Vista, when we launch the subcommands that require administrator privileges (enable, disable and cleanup) we cannot use the administrator launcher binary directly from Java (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6410605) so we use winlauncher.exe. When we launch subcommands that required administrator privileges we must launch a binary containing the manifest that specifies that we require administrator privileges (requireAdministrator value): if UAC is enabled, the user will be asked for confirmation. To minimize the number of confirmation that the user must provide when launching the state subcommand we will use a binary whose manifest does not contain the requireAdministrator value.
See the files under src/build-tools/windows for more details.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConfigureWindowsService.DisableServiceReturnCode
Return codes for the method disableService.static class
ConfigureWindowsService.EnableServiceReturnCode
Return codes for the method enableService.static class
ConfigureWindowsService.StopServiceReturnCode
Return codes for the method stopService.
-
Constructor Summary
Constructors Constructor Description ConfigureWindowsService(OutputStream out, OutputStream err)
Creates a newConfigureWindowsService
with provided streams to log commands output.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.opends.server.tools.ConfigureWindowsService.CleanupServiceReturnCode
cleanupService(String serviceName)
Cleans up a service for a given service name.ConfigureWindowsService.DisableServiceReturnCode
disableService()
Disables OpenDJ to run as a windows service.ConfigureWindowsService.EnableServiceReturnCode
enableService()
Enables OpenDJ to run as a windows service.static boolean
isRunningAsWindowsService()
Returnstrue
if the running server runs as a windows service.static void
main(String[] args)
Configures the Windows service for this instance on this machine.com.forgerock.opendj.cli.ReturnCode
run(String... args)
Configures the Windows service for this instance on this machine.org.opends.server.tools.ConfigureWindowsService.ServiceStateReturnCode
serviceState()
Checks if OpenDJ is enabled as a windows service and if it is write the serviceName in the output stream (if it is not null).org.opends.server.tools.ConfigureWindowsService.StartServiceReturnCode
startService()
Invokes the net start on the service corresponding to this server, it writes information and error messages in the provided streams.ConfigureWindowsService.StopServiceReturnCode
stopService()
Invokes the net stop on the service corresponding to this server, it writes information and error messages in the provided streams.-
Methods inherited from class com.forgerock.opendj.cli.Tool
askPort, close, confirmAction, enableConsoleLoggingIfVerbose, errPrintln, errPrintln, errPrintln, errPrintlnSurroundedByBlankLines, errPrintVerboseMessage, flush, flushLogStream, getErrorStream, getErrStream, getInputStream, getOutputStream, isFullyInteractive, isQuiet, isScriptFriendly, isVerbose, logVerboseMessage, mayPrompt, parseArguments, pressReturnToContinue, print, println, println, println, printlnNoWrap, printlnSurroundedByBlankLines, printNoWrap, readInput, readInput, readInputAllowEmpty, readLineOfInput, readPassword, readValidatedInput, readValidatedInputOrThrow, report
-
-
-
-
Constructor Detail
-
ConfigureWindowsService
public ConfigureWindowsService(OutputStream out, OutputStream err)
Creates a newConfigureWindowsService
with provided streams to log commands output.- Parameters:
out
- The stream to use to log command information messageserr
- The stream to use to log command error messages
-
-
Method Detail
-
main
public static void main(String[] args)
Configures the Windows service for this instance on this machine. This tool allows to enable and disable OpenDJ to run as a Windows service and allows to know if OpenDJ is running as a Windows service or not.- Parameters:
args
- The command-line arguments provided to this program.
-
isRunningAsWindowsService
public static boolean isRunningAsWindowsService()
Returnstrue
if the running server runs as a windows service.- Returns:
true
if the running server runs as a windows service
-
run
public com.forgerock.opendj.cli.ReturnCode run(String... args) throws com.forgerock.opendj.cli.ClientException
Configures the Windows service for this instance on this machine. This tool allows to enable and disable OpenDJ to run as a Windows service and allows to know if OpenDJ is running as a Windows service or not.- Overrides:
run
in classcom.forgerock.opendj.cli.Tool
- Parameters:
args
- The command-line arguments provided to this program.- Returns:
- the integer code describing if the operation could be completed or not.
- Throws:
com.forgerock.opendj.cli.ClientException
- If an error occurs while running the tool.
-
enableService
public ConfigureWindowsService.EnableServiceReturnCode enableService()
Enables OpenDJ to run as a windows service.- Returns:
SERVICE_ENABLE_SUCCESS
,SERVICE_ENABLE_ERROR
,SERVICE_NAME_ALREADY_IN_USE
orSERVICE_ALREADY_ENABLED
depending on whether the service could be enabled or not.
-
disableService
public ConfigureWindowsService.DisableServiceReturnCode disableService()
Disables OpenDJ to run as a windows service.- Returns:
SERVICE_DISABLE_SUCCESS
,SERVICE_DISABLE_ERROR
,SERVICE_MARKED_FOR_DELETION
orSERVICE_ALREADY_DISABLED
depending on whether the service could be disabled or not.
-
cleanupService
public org.opends.server.tools.ConfigureWindowsService.CleanupServiceReturnCode cleanupService(String serviceName)
Cleans up a service for a given service name.- Parameters:
serviceName
- the service name to be cleaned up.- Returns:
SERVICE_CLEANUP_SUCCESS
,SERVICE_NOT_FOUND
,SERVICE_MARKED_FOR_DELETION
orSERVICE_CLEANUP_ERROR
depending on whether the service could be found or not.
-
serviceState
public org.opends.server.tools.ConfigureWindowsService.ServiceStateReturnCode serviceState()
Checks if OpenDJ is enabled as a windows service and if it is write the serviceName in the output stream (if it is not null).- Returns:
SERVICE_STATE_ENABLED
,SERVICE_STATE_DISABLED
orSERVICE_STATE_ERROR
depending on the state of the service.
-
startService
public org.opends.server.tools.ConfigureWindowsService.StartServiceReturnCode startService()
Invokes the net start on the service corresponding to this server, it writes information and error messages in the provided streams.- Returns:
SERVICE_START_SUCCESSFUL
,SERVICE_NOT_FOUND
,SERVICE_ALREADY_STARTED
orSERVICE_START_ERROR
depending on whether the service could be stopped or not.
-
stopService
public ConfigureWindowsService.StopServiceReturnCode stopService()
Invokes the net stop on the service corresponding to this server, it writes information and error messages in the provided streams.- Returns:
SERVICE_STOP_SUCCESSFUL
,SERVICE_NOT_FOUND
orSERVICE_STOP_ERROR
depending on whether the service could be stopped or not.
-
-