Search in sources :

Example 1 with GFLauncherException

use of com.sun.enterprise.admin.launcher.GFLauncherException in project Payara by payara.

the class ChangeAdminPasswordCommand method changeAdminPasswordLocally.

private int changeAdminPasswordLocally(String domainDir, String domainName) throws CommandException {
    if (!isLocalHost(programOpts.getHost())) {
        throw new CommandException(strings.get("CannotExecuteLocally"));
    }
    GFLauncher launcher = null;
    try {
        launcher = GFLauncherFactory.getInstance(RuntimeType.DAS);
        GFLauncherInfo info = launcher.getInfo();
        info.setDomainName(domainName);
        info.setDomainParentDir(domainDir);
        launcher.setup();
        // throw new exception
        if (launcher.isSecureAdminEnabled()) {
            if ((newpassword == null) || (newpassword.isEmpty())) {
                throw new CommandException(strings.get("NullNewPassword"));
            }
        }
        String adminKeyFile = launcher.getAdminRealmKeyFile();
        if (adminKeyFile != null) {
            // This is a FileRealm, instantiate it.
            FileRealmHelper helper = new FileRealmHelper(adminKeyFile);
            // Authenticate the old password
            String[] groups = helper.authenticate(programOpts.getUser(), password.toCharArray());
            if (groups == null) {
                throw new CommandException(strings.get("InvalidCredentials", programOpts.getUser()));
            }
            helper.updateUser(programOpts.getUser(), programOpts.getUser(), newpassword.toCharArray(), null);
            helper.persist();
            return SUCCESS;
        } else {
            // Cannot change password locally for non file realms
            throw new CommandException(strings.get("NotFileRealmCannotChangeLocally"));
        }
    } catch (MiniXmlParserException ex) {
        throw new CommandException(ex);
    } catch (GFLauncherException ex) {
        throw new CommandException(ex);
    } catch (IOException ex) {
        throw new CommandException(ex);
    }
}
Also used : FileRealmHelper(org.glassfish.security.common.FileRealmHelper) GFLauncher(com.sun.enterprise.admin.launcher.GFLauncher) GFLauncherException(com.sun.enterprise.admin.launcher.GFLauncherException) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException) IOException(java.io.IOException) GFLauncherInfo(com.sun.enterprise.admin.launcher.GFLauncherInfo)

Example 2 with GFLauncherException

use of com.sun.enterprise.admin.launcher.GFLauncherException in project Payara by payara.

the class StartServerHelper method waitForServer.

// TODO check the i18n messages
public void waitForServer() throws CommandException {
    long startWait = System.currentTimeMillis();
    if (!terse) {
        // use stdout because logger always appends a newline
        System.out.print(strings.get("WaitServer", serverOrDomainName) + " ");
    }
    boolean alive = false;
    int count = 0;
    pinged: while (!timedOut(startWait)) {
        if (pidFile != null) {
            if (logger.isLoggable(Level.FINER)) {
                logger.finer("Check for pid file: " + pidFile);
            }
            if (pidFile.exists()) {
                alive = true;
                break pinged;
            }
        } else {
            // if it is, the DAS is up
            for (HostAndPort addr : addresses) {
                if (NetUtils.isRunning(addr.getHost(), addr.getPort())) {
                    alive = true;
                    break pinged;
                }
            }
        }
        // if it isn't, startup failed
        try {
            Process p = launcher.getProcess();
            int exitCode = p.exitValue();
            // uh oh, DAS died
            String sname;
            if (info.isDomain()) {
                sname = "domain " + info.getDomainName();
            } else {
                sname = "instance " + info.getInstanceName();
            }
            ProcessStreamDrainer psd = launcher.getProcessStreamDrainer();
            String output = psd.getOutErrString();
            if (ok(output)) {
                throw new CommandException(strings.get("serverDiedOutput", sname, exitCode, output));
            } else {
                throw new CommandException(strings.get("serverDied", sname, exitCode));
            }
        } catch (GFLauncherException ex) {
        // should never happen
        } catch (IllegalThreadStateException ex) {
        // process is still alive
        }
        // wait before checking again
        try {
            Thread.sleep(100);
            if (!terse && count++ % 10 == 0) {
                System.out.print(".");
            }
        } catch (InterruptedException ex) {
        // don't care
        }
    }
    if (!terse) {
        System.out.println();
    }
    if (!alive) {
        String msg;
        String time = "" + (WAIT_FOR_DAS_TIME_MS / 1000);
        if (info.isDomain()) {
            msg = strings.get("serverNoStart", strings.get("DAS"), info.getDomainName(), time);
        } else {
            msg = strings.get("serverNoStart", strings.get("INSTANCE"), info.getInstanceName(), time);
        }
        throw new CommandException(msg);
    }
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) ProcessStreamDrainer(com.sun.enterprise.universal.process.ProcessStreamDrainer) GFLauncherException(com.sun.enterprise.admin.launcher.GFLauncherException) CommandException(org.glassfish.api.admin.CommandException)

Example 3 with GFLauncherException

use of com.sun.enterprise.admin.launcher.GFLauncherException in project Payara by payara.

the class StartLocalInstanceCommand method executeCommand.

/**
 */
@Override
protected int executeCommand() throws CommandException {
    if (logger.isLoggable(Level.FINER))
        logger.finer(toString());
    if (sync.equals("none")) {
        logger.info(Strings.get("Instance.nosync"));
    } else {
        if (!synchronizeInstance()) {
            File domainXml = new File(new File(instanceDir, "config"), "domain.xml");
            if (!domainXml.exists()) {
                logger.info(Strings.get("Instance.nodomainxml"));
                return ERROR;
            }
            logger.info(Strings.get("Instance.syncFailed"));
        }
    }
    try {
        // createLauncher needs to go before the helper is created!!
        createLauncher();
        final String mpv = getMasterPassword();
        helper = new StartServerHelper(logger, programOpts.isTerse(), getServerDirs(), launcher, mpv, debug);
        if (!helper.prepareForLaunch()) {
            return ERROR;
        }
        if (dry_run) {
            if (logger.isLoggable(Level.FINE))
                logger.fine(Strings.get("dry_run_msg"));
            List<String> cmd = getLauncher().getCommandLine();
            StringBuilder sb = new StringBuilder();
            for (String s : cmd) {
                sb.append(s);
                sb.append('\n');
            }
            logger.info(sb.toString());
            return SUCCESS;
        }
        getLauncher().launch();
        if (verbose || watchdog) {
            // we can potentially loop forever here...
            while (true) {
                int returnValue = getLauncher().getExitValue();
                switch(returnValue) {
                    case RESTART_NORMAL:
                        logger.info(Strings.get("restart"));
                        break;
                    case RESTART_DEBUG_ON:
                        logger.info(Strings.get("restartChangeDebug", "on"));
                        getInfo().setDebug(true);
                        break;
                    case RESTART_DEBUG_OFF:
                        logger.info(Strings.get("restartChangeDebug", "off"));
                        getInfo().setDebug(false);
                        break;
                    default:
                        return returnValue;
                }
                if (env.debug())
                    System.setProperty(CLIConstants.WALL_CLOCK_START_PROP, "" + System.currentTimeMillis());
                getLauncher().relaunch();
            }
        } else {
            helper.waitForServer();
            helper.report();
            return SUCCESS;
        }
    } catch (GFLauncherException gfle) {
        throw new CommandException(gfle.getMessage());
    } catch (MiniXmlParserException me) {
        throw new CommandException(me);
    }
}
Also used : StartServerHelper(com.sun.enterprise.admin.servermgmt.cli.StartServerHelper) GFLauncherException(com.sun.enterprise.admin.launcher.GFLauncherException) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException)

Aggregations

GFLauncherException (com.sun.enterprise.admin.launcher.GFLauncherException)3 MiniXmlParserException (com.sun.enterprise.universal.xml.MiniXmlParserException)2 GFLauncher (com.sun.enterprise.admin.launcher.GFLauncher)1 GFLauncherInfo (com.sun.enterprise.admin.launcher.GFLauncherInfo)1 StartServerHelper (com.sun.enterprise.admin.servermgmt.cli.StartServerHelper)1 ProcessStreamDrainer (com.sun.enterprise.universal.process.ProcessStreamDrainer)1 HostAndPort (com.sun.enterprise.util.HostAndPort)1 IOException (java.io.IOException)1 CommandException (org.glassfish.api.admin.CommandException)1 FileRealmHelper (org.glassfish.security.common.FileRealmHelper)1