Skip to content

Commit

Permalink
[VUFIND-1568] Make Solr port configurable during installation (vufind…
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz authored Aug 4, 2023
1 parent bc58056 commit bf7db8c
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
ChangeLog
TAGS
composer.phar
env.bat
env.sh
import/solrmarc.log*
lessphp_*.list
module/VuFind/tests/.phpunit.result.cache
Expand Down
54 changes: 46 additions & 8 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<property name="solr_startup_sleep" value="0" />
<property name="solr_additional_jvm_options" value="-Dlog4j2.formatMsgNoLookups=true" />
<property name="solr_version" value="9.1.1" />
<property name="solr_port" value="8983" />
<property name="skip_phpdoc" value="false" />
<property name="phpdoc_version" value="3.3.1" />
<property name="html_validator" value="" /><!-- set to base address of NU Validator (e.g. http://localhost:8888/) for HTML validation during Mink tests -->
Expand Down Expand Up @@ -272,7 +273,7 @@
<property name="paramCoverageDir" value="" />
</else>
</if>
<exec dir="${srcdir}/module/VuFind/tests" command="XDEBUG_MODE=coverage VUFIND_MINK_DRIVER=${mink_driver} VUFIND_SCREENSHOT_DIR=${screenshot_dir} ${phpunit_html_validation_params} VUFIND_SELENIUM_BROWSER=${selenium_browser} VUFIND_SNOOZE_MULTIPLIER=${snooze_multiplier} VUFIND_LOCAL_DIR=${localdir} VUFIND_URL=${vufindurl} ${paramCoverageDir} ${phpunit_command} --log-junit ${builddir}/reports/phpunit.xml --coverage-php ${coveragedir}/tmp/unit.cov ${phpunit_extra_params}" passthru="true" checkreturn="true" />
<exec dir="${srcdir}/module/VuFind/tests" command="XDEBUG_MODE=coverage VUFIND_MINK_DRIVER=${mink_driver} VUFIND_SCREENSHOT_DIR=${screenshot_dir} ${phpunit_html_validation_params} VUFIND_SELENIUM_BROWSER=${selenium_browser} VUFIND_SNOOZE_MULTIPLIER=${snooze_multiplier} VUFIND_LOCAL_DIR=${localdir} VUFIND_URL=${vufindurl} SOLR_PORT=${solr_port} ${paramCoverageDir} ${phpunit_command} --log-junit ${builddir}/reports/phpunit.xml --coverage-php ${coveragedir}/tmp/unit.cov ${phpunit_extra_params}" passthru="true" checkreturn="true" />

<!-- Produce coverage reports -->
<exec command="${srcdir}/vendor/bin/phpcov merge --clover ${coveragedir}/clover.xml --html ${coveragedir} ${coveragedir}/tmp" passthru="true" checkreturn="true" />
Expand All @@ -292,12 +293,12 @@

<!-- PHPUnit without logging output -->
<target name="phpunitfast" description="Run tests">
<exec dir="${srcdir}/module/VuFind/tests" command="VUFIND_MINK_DRIVER=${mink_driver} VUFIND_SCREENSHOT_DIR=${screenshot_dir} ${phpunit_html_validation_params} VUFIND_SELENIUM_BROWSER=${selenium_browser} VUFIND_SNOOZE_MULTIPLIER=${snooze_multiplier} VUFIND_LOCAL_DIR=${localdir} VUFIND_URL=${vufindurl} ${phpunit_command} ${phpunit_extra_params}" passthru="true" checkreturn="true" />
<exec dir="${srcdir}/module/VuFind/tests" command="VUFIND_MINK_DRIVER=${mink_driver} VUFIND_SCREENSHOT_DIR=${screenshot_dir} ${phpunit_html_validation_params} VUFIND_SELENIUM_BROWSER=${selenium_browser} VUFIND_SNOOZE_MULTIPLIER=${snooze_multiplier} VUFIND_LOCAL_DIR=${localdir} VUFIND_URL=${vufindurl} SOLR_PORT=${solr_port} ${phpunit_command} ${phpunit_extra_params}" passthru="true" checkreturn="true" />
</target>

<!-- PHPUnit without logging output, stopping at first error or failure -->
<target name="phpunitfaster" description="Run tests until first failure">
<exec dir="${srcdir}/module/VuFind/tests" command="VUFIND_MINK_DRIVER=${mink_driver} VUFIND_SCREENSHOT_DIR=${screenshot_dir} ${phpunit_html_validation_params} VUFIND_SELENIUM_BROWSER=${selenium_browser} VUFIND_SNOOZE_MULTIPLIER=${snooze_multiplier} VUFIND_LOCAL_DIR=${localdir} VUFIND_URL=${vufindurl} ${phpunit_command} --stop-on-failure ${phpunit_extra_params}" passthru="true" checkreturn="true" />
<exec dir="${srcdir}/module/VuFind/tests" command="VUFIND_MINK_DRIVER=${mink_driver} VUFIND_SCREENSHOT_DIR=${screenshot_dir} ${phpunit_html_validation_params} VUFIND_SELENIUM_BROWSER=${selenium_browser} VUFIND_SNOOZE_MULTIPLIER=${snooze_multiplier} VUFIND_LOCAL_DIR=${localdir} VUFIND_URL=${vufindurl} SOLR_PORT=${solr_port} ${phpunit_command} --stop-on-failure ${phpunit_extra_params}" passthru="true" checkreturn="true" />
</target>

<target name="installsolr" description="Install Solr">
Expand Down Expand Up @@ -400,14 +401,26 @@

<!-- Install and Activate VuFind -->
<target name="startup" description="install and activate demo">
<property name="solr_pid_file" value="${localdir}/solr-8983.pid" />
<property name="solr_pid_file" value="${localdir}/solr-${solr_port}.pid" />
<!-- fail if the system is already running -->
<if>
<available file="${solr_pid_file}" />
<then>
<fail>Solr PID file (${solr_pid_file}) detected. Is the system already running?</fail>
</then>
</if>
<if>
<available file="${srcdir}/env.bat" />
<then>
<fail>Environment file (env.bat) detected. Is the system already running?</fail>
</then>
</if>
<if>
<available file="${srcdir}/env.sh" />
<then>
<fail>Environment file (env.sh) detected. Is the system already running?</fail>
</then>
</if>

<phingcall target="check_local_config" />

Expand Down Expand Up @@ -484,7 +497,7 @@

<!-- Generate basic configuration -->
<php expression="end(explode('/', '${vufindurl}'))" returnProperty="basepath" />
<exec command="php ${srcdir}/install.php --basepath=/${basepath} --non-interactive" passthru="true" checkreturn="true" />
<exec command="php ${srcdir}/install.php --basepath=/${basepath} --non-interactive --solr-port=${solr_port}" passthru="true" checkreturn="true" />

<!-- Update config.ini to activate DB connection, exception logging and test mode -->
<if>
Expand All @@ -503,6 +516,15 @@
<regexp pattern="mysql://root@localhost/vufind" replace="${db_connection_string}" />
<regexp pattern=";file\s+= /var/log/vufind.log:alert,error,notice,debug" replace="file = ${srcdir}/vufind-exception.log:alert-5,error-5" />
<regexp pattern="(\[System\]\s+)" replace="\1runningTestSuite=1" />
<regexp pattern="(url\s+= http://localhost):8983/solr" replace="\1:${solr_port}/solr" />
</replaceregexp>
</filterchain>
</copy>

<copy file="${srcdir}/config/vufind/Search2.ini" tofile="${localdir}/config/vufind/Search2.ini">
<filterchain>
<replaceregexp>
<regexp pattern="(url\s+= http://localhost):8983/solr" replace="\1:${solr_port}/solr" />
</replaceregexp>
</filterchain>
</copy>
Expand Down Expand Up @@ -562,7 +584,7 @@
<!-- Set up Solr -->
<target name="setup_solr">
<!-- Start Solr using restart in case of old PID files -->
<exec command="SOLR_PID_DIR=${localdir} VUFIND_HOME=${srcdir} SOLR_ADDITIONAL_JVM_OPTIONS=${solr_additional_jvm_options} ${srcdir}/solr.sh restart" passthru="true" checkreturn="true" />
<exec command="SOLR_PID_DIR=${localdir} VUFIND_HOME=${srcdir} SOLR_ADDITIONAL_JVM_OPTIONS=${solr_additional_jvm_options} SOLR_PORT=${solr_port} ${srcdir}/solr.sh restart" passthru="true" checkreturn="true" />
<!-- fail if Solr did not start up successfully: -->
<if>
<not><available file="${solr_pid_file}" /></not>
Expand Down Expand Up @@ -646,7 +668,7 @@ ${git_status}
</if>

<!-- stop Solr -->
<exec command="SOLR_PID_DIR=${localdir} VUFIND_HOME=${srcdir} SOLR_ADDITIONAL_JVM_OPTIONS=${solr_additional_jvm_options} ${srcdir}/solr.sh stop" passthru="true" />
<exec command="SOLR_PID_DIR=${localdir} VUFIND_HOME=${srcdir} SOLR_ADDITIONAL_JVM_OPTIONS=${solr_additional_jvm_options} SOLR_PORT=${solr_port} ${srcdir}/solr.sh stop" passthru="true" />

<!-- run extra cleanup action, if any -->
<if>
Expand All @@ -667,6 +689,18 @@ ${git_status}
</if>

<!-- delete the configuration, sample index, logs and cache data -->
<if>
<available file="${srcdir}/env.bat" />
<then>
<delete file="${srcdir}/env.bat" failonerror="true" />
</then>
</if>
<if>
<available file="${srcdir}/env.sh" />
<then>
<delete file="${srcdir}/env.sh" failonerror="true" />
</then>
</if>
<if>
<available file="${srcdir}/import/solrmarc.log" />
<then>
Expand Down Expand Up @@ -711,7 +745,7 @@ ${git_status}

<!-- Reset database and configuration of the demo setup -->
<target name="reset_setup" description="reset configuration and database of demo">
<property name="solr_pid_file" value="${localdir}/solr-8983.pid" />
<property name="solr_pid_file" value="${localdir}/solr-${solr_port}.pid" />
<!-- fail if the system is not already running -->
<if>
<not><available file="${solr_pid_file}" /></not>
Expand Down Expand Up @@ -739,6 +773,10 @@ ${git_status}
<include name="*" />
</fileset>
</delete>
<delete file="${srcdir}/env.bat" />
<delete file="${srcdir}/env.sh" />
<delete file="${localdir}/import/import.properties" />
<delete file="${localdir}/import/import_auth.properties" />

<phingcall target="configure_install" />
<phingcall target="setup_database" />
Expand Down
26 changes: 26 additions & 0 deletions module/VuFind/src/VuFind/Controller/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ protected function checkBasicConfig()
];
}

/**
* Extract the Solr base URL from the SolrMarc configuration file,
* so a custom Solr port configured in install.php can be applied to
* the initial config.ini file.
*
* Return null if no custom Solr URL can be found.
*
* @return ?string
*/
protected function getSolrUrlFromImportConfig()
{
$resolver = $this->serviceLocator->get(\VuFind\Config\PathResolver::class);
$importConfig = $resolver->getLocalConfigPath('import.properties', 'import');
if (file_exists($importConfig)) {
$props = file_get_contents($importConfig);
preg_match('|solr.hosturl\s*=\s*(https?://\w+:\d+/\w+)|', $props, $matches);
if (!empty($matches[1])) {
return $matches[1];
}
}
return null;
}

/**
* Display repair instructions for basic configuration problems.
*
Expand All @@ -152,6 +175,9 @@ public function fixbasicconfigAction()
$serverUrl = $this->getViewRenderer()->plugin('serverurl');
$path = $this->url()->fromRoute('home');
$writer->set('Site', 'url', rtrim($serverUrl($path), '/'));
if ($solrUrl = $this->getSolrUrlFromImportConfig()) {
$writer->set('Index', 'url', $solrUrl);
}
if (!$writer->save()) {
throw new \Exception('Cannot write config to disk.');
}
Expand Down
3 changes: 2 additions & 1 deletion module/VuFind/src/VuFindTest/Feature/LiveDetectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ trait LiveDetectionTrait
public function continuousIntegrationRunning()
{
// We'll assume that if the CI Solr PID is present, then CI is active:
return file_exists(__DIR__ . '/../../../../../local/solr-8983.pid');
$port = getenv('SOLR_PORT') ?? '8983';
return file_exists(__DIR__ . "/../../../../../local/solr-$port.pid");
}
}
Loading

0 comments on commit bf7db8c

Please sign in to comment.