Class 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.

    • Constructor Detail

      • ConfigureWindowsService

        public ConfigureWindowsService​(OutputStream out,
                                       OutputStream err)
        Creates a new ConfigureWindowsService with provided streams to log commands output.
        Parameters:
        out - The stream to use to log command information messages
        err - 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()
        Returns true 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 class com.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 or SERVICE_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 or SERVICE_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 or SERVICE_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 or SERVICE_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 or SERVICE_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 or SERVICE_STOP_ERROR depending on whether the service could be stopped or not.