Search in sources :

Example 1 with LocalConfig

use of com.zimbra.common.localconfig.LocalConfig in project zm-mailbox by Zimbra.

the class MailPort method postModify.

@Override
public void postModify(CallbackContext context, String attrName, Entry entry) {
    super.postModify(context, attrName, entry);
    if (entry instanceof Server) {
        Server localServer = null;
        try {
            localServer = Provisioning.getInstance().getLocalServer();
            if (entry == localServer) {
                String port = localServer.getAttr(attrName);
                LocalConfig lc = new LocalConfig(null);
                lc.set(LC.zimbra_mail_service_port.key(), port);
                lc.save();
            }
        } catch (ServiceException | DocumentException | ConfigException | NumberFormatException | IOException e) {
            ZimbraLog.misc.warn("Unable to update LC.zimbra_mail_port due to Exception", e);
        }
    }
}
Also used : Server(com.zimbra.cs.account.Server) ServiceException(com.zimbra.common.service.ServiceException) LocalConfig(com.zimbra.common.localconfig.LocalConfig) DocumentException(org.dom4j.DocumentException) ConfigException(com.zimbra.common.localconfig.ConfigException) IOException(java.io.IOException)

Example 2 with LocalConfig

use of com.zimbra.common.localconfig.LocalConfig in project zm-mailbox by Zimbra.

the class LocalConfigCLI method exec.

private void exec(String[] args) {
    CommandLine cl = null;
    CommandLineParser parser = new GnuParser();
    try {
        cl = parser.parse(mOptions, args);
    } catch (ParseException pe) {
        Logging.error("Failed to parse command line: " + pe);
        System.exit(1);
    }
    if (cl.hasOption("q")) {
        Logging.setQuietMode(true);
    }
    if (cl.hasOption("h")) {
        usage();
    }
    // Load known keys from BackupLC if available
    loadExtensionLC("com.zimbra.cs.backup.BackupLC");
    // Load known keys from ZimbraOpenOfficeExt if available
    loadExtensionLC("com.zimbra.openoffice.config.OpenOfficeLC");
    // Load known keys from ZimbraVoice if available
    loadExtensionLC("com.zimbra.cs.voice.VoiceLC");
    // info/docs for supported keys
    if (cl.hasOption("i")) {
        checkCompatibleOptions("i", "q", cl);
        LocalConfig.printDoc(System.out, cl.getArgs(), false);
        return;
    }
    // info/docs for all keys (hidden option)
    if (cl.hasOption("all")) {
        checkCompatibleOptions("all", "q", cl);
        LocalConfig.printDoc(System.out, cl.getArgs(), true);
        return;
    }
    LocalConfig lc = null;
    try {
        lc = new LocalConfig(cl.getOptionValue("c"));
    } catch (DocumentException de) {
        error("failed when reading config file", de);
    } catch (ConfigException ce) {
        error("failed with error in config file", ce);
    }
    // edit
    if (cl.hasOption("e")) {
        checkNotRoot("-e");
        checkCompatibleOptions("e", "qfrc", cl);
        String[] av = cl.getArgs();
        if (av == null || av.length == 0) {
            error("insufficient arguments", null);
        }
        for (int i = 0; i < av.length; i++) {
            String key = null;
            String value = null;
            if (cl.hasOption("r")) {
                key = av[i];
                value = RandomPassword.generate();
            } else {
                int eqidx = av[i].indexOf("=");
                if (eqidx <= 0) {
                    // <= 0 also catches first char being =, ie no key specified
                    error("argument '" + av[i] + "' not in key=value form", null);
                }
                key = av[i].substring(0, eqidx);
                value = av[i].substring(eqidx + 1, av[i].length());
            }
            if (KnownKey.needForceToEdit(key) && !cl.hasOption("f")) {
                error("can not edit key " + key, null);
            }
            lc.set(key, value);
        }
        try {
            lc.save();
        } catch (Exception e) {
            error("save to " + lc.getConfigFile() + " failed", e);
        }
        return;
    }
    // unset
    if (cl.hasOption("u")) {
        checkNotRoot("-u");
        checkCompatibleOptions("u", "qfc", cl);
        String[] av = cl.getArgs();
        if (av == null || av.length == 0) {
            error("insufficient arguments", null);
        }
        for (int i = 0; i < av.length; i++) {
            String key = av[i];
            if (!lc.isSet(key)) {
                error("key " + key + " is not set", null);
            }
            lc.remove(key);
        }
        try {
            lc.save();
        } catch (Exception e) {
            error("save to " + lc.getConfigFile() + " failed", e);
        }
        return;
    }
    // show path
    if (cl.hasOption("p")) {
        checkCompatibleOptions("p", "qc", cl);
        System.out.println(lc.getConfigFile());
        return;
    }
    if (cl.hasOption("l")) {
        // reset logging and run native lib load
        CliUtil.toolSetup("WARN");
        try {
            reload();
        } catch (ServiceException e) {
            if (e.getCause() instanceof ConnectException) {
                error("'" + Provisioning.SERVICE_MAILBOX + "' service is not running", null);
            } else {
                error(e.getMessage(), e);
            }
        }
        return;
    }
    // print values
    String format = cl.getOptionValue("m");
    ConfigWriter cwriter = null;
    try {
        cwriter = ConfigWriter.getInstance(format, cl.hasOption("x"), !cl.hasOption("s"));
    } catch (ConfigException iae) {
        error("failed to create writer " + format, iae);
    }
    try {
        // changed
        if (cl.hasOption("n")) {
            checkCompatibleOptions("n", "qscmx", cl);
            lc.printChanged(System.out, cwriter, cl.getArgs());
            return;
        }
        // default
        if (cl.hasOption("d")) {
            checkCompatibleOptions("d", "qscmx", cl);
            lc.printDefaults(System.out, cwriter, cl.getArgs());
            return;
        }
        // current
        checkCompatibleOptions("", "qscmx", cl);
        lc.print(System.out, cwriter, cl.getArgs());
    } catch (Exception e) {
        error("exception occurred when printing", e);
    }
}
Also used : LocalConfig(com.zimbra.common.localconfig.LocalConfig) GnuParser(org.apache.commons.cli.GnuParser) ConfigException(com.zimbra.common.localconfig.ConfigException) ServiceException(com.zimbra.common.service.ServiceException) DocumentException(org.dom4j.DocumentException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) ConfigException(com.zimbra.common.localconfig.ConfigException) ZClientException(com.zimbra.common.zclient.ZClientException) ConfigWriter(com.zimbra.common.localconfig.ConfigWriter) CommandLine(org.apache.commons.cli.CommandLine) ServiceException(com.zimbra.common.service.ServiceException) DocumentException(org.dom4j.DocumentException) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) ConnectException(java.net.ConnectException)

Example 3 with LocalConfig

use of com.zimbra.common.localconfig.LocalConfig in project zm-mailbox by Zimbra.

the class Zimbra method startup.

/**
     * Initialize the various subsystems at server/CLI startup time.
     * @param forMailboxd true if this is the mailboxd process; false for CLI processes
     * @throws ServiceException
     */
private static synchronized void startup(boolean forMailboxd) throws ServiceException {
    if (sInited)
        return;
    sIsMailboxd = forMailboxd;
    if (sIsMailboxd) {
        FirstServlet.waitForInitialization();
    }
    Provisioning prov = Provisioning.getInstance();
    Server server = prov.getLocalServer();
    alwaysOnClusterId = server.getAlwaysOnClusterId();
    setSystemProperties();
    validateJavaOptions();
    logVersionAndSysInfo();
    SoapTransport.setDefaultUserAgent("ZCS", BuildInfo.VERSION);
    checkForClasses();
    ZimbraApplication app = ZimbraApplication.getInstance();
    DbPool.startup();
    app.initializeZimbraDb(forMailboxd);
    if (!Versions.checkVersions()) {
        Zimbra.halt("Data version mismatch.  Reinitialize or upgrade the backend data store.");
    }
    DbPool.loadSettings();
    String tzFilePath = LC.timezone_file.value();
    try {
        File tzFile = new File(tzFilePath);
        WellKnownTimeZones.loadFromFile(tzFile);
    } catch (Throwable t) {
        Zimbra.halt("Unable to load timezones from " + tzFilePath, t);
    }
    if (prov instanceof LdapProv) {
        ((LdapProv) prov).waitForLdapServer();
        if (forMailboxd) {
            AttributeManager.loadLdapSchemaExtensionAttrs((LdapProv) prov);
        }
    }
    if (server.isMailSSLClientCertOCSPEnabled()) {
        // Activate OCSP
        Security.setProperty("ocsp.enable", "true");
        // Activate CRLDP
        System.setProperty("com.sun.security.enableCRLDP", "true");
    } else {
        // Disable OCSP
        Security.setProperty("ocsp.enable", "false");
        // Disable CRLDP
        System.setProperty("com.sun.security.enableCRLDP", "false");
    }
    try {
        RightManager.getInstance();
    } catch (ServiceException e) {
        Util.halt("cannot initialize RightManager", e);
    }
    ZimbraHttpConnectionManager.startReaperThread();
    EphemeralStore.registerFactory("ldap", LdapEphemeralStore.Factory.class.getName());
    ExtensionUtil.initAll();
    try {
        StoreManager.getInstance().startup();
    } catch (IOException e) {
        throw ServiceException.FAILURE("Unable to initialize StoreManager.", e);
    }
    MailboxManager.getInstance();
    app.startup();
    if (app.supports(MemcachedConnector.class.getName())) {
        MemcachedConnector.startup();
    }
    if (app.supports(EhcacheManager.class.getName())) {
        EhcacheManager.getInstance().startup();
    }
    // ZimletUtil.loadZimlets();
    MailboxIndex.startup();
    RedoLogProvider redoLog = RedoLogProvider.getInstance();
    if (sIsMailboxd) {
        redoLog.startup();
    } else {
        redoLog.initRedoLogManager();
    }
    System.setProperty("ical4j.unfolding.relaxed", "true");
    MailboxManager.getInstance().startup();
    app.initialize(sIsMailboxd);
    if (sIsMailboxd) {
        SessionCache.startup();
        AuthTokenRegistry.startup(prov.getConfig(Provisioning.A_zimbraAuthTokenNotificationInterval).getIntAttr(Provisioning.A_zimbraAuthTokenNotificationInterval, 60000));
        dbSessionCleanup();
        if (!redoLog.isSlave()) {
            boolean useDirectBuffers = server.isMailUseDirectBuffers();
            IoBuffer.setUseDirectBuffer(useDirectBuffers);
            ZimbraLog.misc.info("MINA setUseDirectBuffers(" + useDirectBuffers + ")");
            ServerManager.getInstance().startServers();
        }
        if (app.supports(WaitSetMgr.class.getName())) {
            WaitSetMgr.startup();
        }
        if (app.supports(MemoryStats.class.getName())) {
            MemoryStats.startup();
        }
        if (app.supports(ScheduledTaskManager.class.getName())) {
            ScheduledTaskManager.startup();
        }
        if (app.supports(PurgeThread.class.getName())) {
            PurgeThread.startup();
        }
        if (app.supports(AutoProvisionThread.class.getName())) {
            AutoProvisionThread.switchAutoProvThreadIfNecessary();
        }
        if (LC.smtp_to_lmtp_enabled.booleanValue()) {
            int smtpPort = LC.smtp_to_lmtp_port.intValue();
            int lmtpPort = Provisioning.getInstance().getLocalServer().getLmtpBindPort();
            SmtpToLmtp smtpServer = SmtpToLmtp.startup(smtpPort, "localhost", lmtpPort);
            smtpServer.setRecipientValidator(new SmtpRecipientValidator());
        }
        if (app.supports(AclPushTask.class)) {
            long pushInterval = server.getSharingUpdatePublishInterval();
            sTimer.schedule(new AclPushTask(), pushInterval, pushInterval);
        }
        if (app.supports(ExternalAccountManagerTask.class)) {
            long interval = server.getExternalAccountStatusCheckInterval();
            sTimer.schedule(new ExternalAccountManagerTask(), interval, interval);
        }
        if (prov.getLocalServer().isMessageChannelEnabled()) {
            try {
                MessageChannel.getInstance().startup();
            } catch (IOException e) {
                ZimbraLog.misc.warn("can't start notification channels", e);
            }
        }
        Server localServer = Provisioning.getInstance().getLocalServer();
        String provPort = localServer.getAttr(Provisioning.A_zimbraMailPort);
        String lcPort = LC.zimbra_mail_service_port.value();
        if (!lcPort.equals(provPort)) {
            LocalConfig lc;
            try {
                lc = new LocalConfig(null);
                lc.set(LC.zimbra_mail_service_port.key(), provPort);
                lc.save();
                LC.reload();
            } catch (DocumentException | ConfigException | IOException e) {
                ZimbraLog.misc.warn("Cannot set LC zimbra_mail_service_port", e);
            }
        }
        // should be last, so that other subsystems can add dynamic stats counters
        if (app.supports(ZimbraPerf.class.getName())) {
            ZimbraPerf.initialize();
        }
    }
    ExtensionUtil.postInitAll();
    // Register the service with ZooKeeper
    if (sIsMailboxd && isAlwaysOn()) {
        try {
            CuratorManager curatorManager = CuratorManager.getInstance();
            if (curatorManager == null) {
                throw ServiceException.FAILURE("ZooKeeper addresses not configured.", null);
            }
            curatorManager.start();
        } catch (Exception e) {
            throw ServiceException.FAILURE("Unable to start Distributed Lock service.", e);
        }
    }
    sInited = true;
}
Also used : PurgeThread(com.zimbra.cs.mailbox.PurgeThread) Server(com.zimbra.cs.account.Server) AclPushTask(com.zimbra.cs.mailbox.acl.AclPushTask) ConfigException(com.zimbra.common.localconfig.ConfigException) Provisioning(com.zimbra.cs.account.Provisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv) AutoProvisionThread(com.zimbra.cs.account.AutoProvisionThread) ScheduledTaskManager(com.zimbra.cs.mailbox.ScheduledTaskManager) RedoLogProvider(com.zimbra.cs.redolog.RedoLogProvider) DocumentException(org.dom4j.DocumentException) ExternalAccountManagerTask(com.zimbra.cs.account.ExternalAccountManagerTask) SmtpToLmtp(com.zimbra.common.lmtp.SmtpToLmtp) MemcachedConnector(com.zimbra.cs.memcached.MemcachedConnector) LocalConfig(com.zimbra.common.localconfig.LocalConfig) IOException(java.io.IOException) ServiceException(com.zimbra.common.service.ServiceException) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException) ConfigException(com.zimbra.common.localconfig.ConfigException) WaitSetMgr(com.zimbra.cs.session.WaitSetMgr) ServiceException(com.zimbra.common.service.ServiceException) ZimbraPerf(com.zimbra.cs.stats.ZimbraPerf) CuratorManager(com.zimbra.cs.zookeeper.CuratorManager) File(java.io.File)

Example 4 with LocalConfig

use of com.zimbra.common.localconfig.LocalConfig in project zm-mailbox by Zimbra.

the class TestUtil method setLCValue.

protected static void setLCValue(KnownKey key, String newValue) throws DocumentException, ConfigException, IOException, ServiceException {
    LocalConfig lc = new LocalConfig(null);
    if (newValue == null) {
        lc.remove(key.key());
    } else {
        lc.set(key.key(), newValue);
    }
    lc.save();
    SoapProvisioning prov = TestUtil.newSoapProvisioning();
    ReloadLocalConfigRequest req = new ReloadLocalConfigRequest();
    ReloadLocalConfigResponse resp = prov.invokeJaxb(req);
    assertNotNull("ReloadLocalConfigResponse", resp);
}
Also used : ReloadLocalConfigResponse(com.zimbra.soap.admin.message.ReloadLocalConfigResponse) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) LocalConfig(com.zimbra.common.localconfig.LocalConfig) ReloadLocalConfigRequest(com.zimbra.soap.admin.message.ReloadLocalConfigRequest)

Aggregations

LocalConfig (com.zimbra.common.localconfig.LocalConfig)4 ConfigException (com.zimbra.common.localconfig.ConfigException)3 ServiceException (com.zimbra.common.service.ServiceException)3 IOException (java.io.IOException)3 DocumentException (org.dom4j.DocumentException)3 Server (com.zimbra.cs.account.Server)2 SmtpToLmtp (com.zimbra.common.lmtp.SmtpToLmtp)1 ConfigWriter (com.zimbra.common.localconfig.ConfigWriter)1 ZClientException (com.zimbra.common.zclient.ZClientException)1 AutoProvisionThread (com.zimbra.cs.account.AutoProvisionThread)1 ExternalAccountManagerTask (com.zimbra.cs.account.ExternalAccountManagerTask)1 Provisioning (com.zimbra.cs.account.Provisioning)1 LdapProv (com.zimbra.cs.account.ldap.LdapProv)1 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)1 PurgeThread (com.zimbra.cs.mailbox.PurgeThread)1 ScheduledTaskManager (com.zimbra.cs.mailbox.ScheduledTaskManager)1 AclPushTask (com.zimbra.cs.mailbox.acl.AclPushTask)1 MemcachedConnector (com.zimbra.cs.memcached.MemcachedConnector)1 RedoLogProvider (com.zimbra.cs.redolog.RedoLogProvider)1 WaitSetMgr (com.zimbra.cs.session.WaitSetMgr)1