Skip to content

Instantly share code, notes, and snippets.

@phillipuniverse
Created October 23, 2020 17:10
Show Gist options
  • Save phillipuniverse/34479110028d7ce1ee5283eea1bd5cdd to your computer and use it in GitHub Desktop.
Save phillipuniverse/34479110028d7ce1ee5283eea1bd5cdd to your computer and use it in GitHub Desktop.
package org.broadleafoverrides.config;
import com.broadleafcommerce.solr.autoconfigure.SolrProperties;
import com.broadleafcommerce.solr.autoconfigure.SolrServer;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.Executor;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
@Configuration
public class BroadleafOverrides {
@Bean
public ForceStartupSolrServer blAutoSolrServer(SolrProperties props) {
return new ForceStartupSolrServer(props);
}
static class ForceStartupSolrServer extends SolrServer {
private static final Log LOG = LogFactory.getLog(SolrServer.class);
public ForceStartupSolrServer(SolrProperties props) {
super(props);
}
protected void startSolr() {
if (!isRunning()) {
LOG.info("-----DOWNLOADING SOLR-----");
if (!downloadSolrIfApplicable()) {
throw new IllegalStateException("Could not download or expand Solr, see previous logs for more information");
}
stopSolr();
synchConfig();
{
CommandLine cmdLine = new CommandLine(getSolrCommand());
cmdLine.addArgument("start");
cmdLine.addArgument("-p");
cmdLine.addArgument(Integer.toString(props.getPort()));
// START MODIFICATION
cmdLine.addArgument("-force");
// END MODIFICATION
Executor executor = new DefaultExecutor();
PumpStreamHandler streamHandler = new PumpStreamHandler(System.out);
streamHandler.setStopTimeout(1000);
executor.setStreamHandler(streamHandler);
try {
executor.execute(cmdLine);
created = true;
checkCoreStatus();
} catch (IOException e) {
LOG.error("Problem starting Solr", e);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment