About Features Downloads Getting Started Documentation Events Support GitHub

Love VuFind®? Consider becoming a financial supporter. Your support helps build a better VuFind®!

Site Tools


Warning: This page has not been updated in over over a year and may be outdated or deprecated.
installation:installing_multiple_instances:automation_example

Multiple Instances Automation Example

This example provides a working script to automate the creation of multiple VuFind instances.

Background

Suppose you were running a web hosting service, and you wanted to give every user their own VuFind instance, but without installing a separate copy of the software for each user, and without allowing any users to access or change other users' data.

VuFind supports this scenario: you can install the software once, set up a host-based multi-site, give each user their own hostname, and then set up a MySQL database, Solr core, VuFind code module, VuFind theme and VuFind local configuration directory for each user. Through a bit of symbolic linking, you can expose all of these resources through each user's home directory, making it convenient to reach all of the relevant parts from a single place. By setting the right environment variables in the user's ~/.profile file, you ensure that they have the appropriate context every time they log in.

About the Script

The script below was designed to automate all of this setup work. It was developed and tested with VuFind 7.0 under Ubuntu 20.04, but it should work with other versions with only minor changes. All of the naming and directory mapping is set up using variables, so it should be fairly easy to customize for differing needs.

Using the Script

Step by Step:

  1. Copy the code below into a file, and make that file executable; these notes assume you've put the code in $VUFIND_HOME/make-local-site.sh.
  2. Make sure you have edited all relevant variables with appropriate values; the MySQL credentials, VuFind home directory and Solr user are especially important to get right.
  3. For each user-based VuFind site you want to set up, simply run “sudo ./make-local-site.sh <username>”
  4. After all of the sites have been set up, restart the Solr and Apache services to load the new cores and configurations that have been created.

Notes:

  • As currently coded, each user's VuFind site will be at the URL “http://username.hostname/vufind,” where hostname is determined by the BASE_DOMAIN variable in the script. It should be possible to use a directory-based multi-site instead with minor changes to the install.php call in the script.
  • The script does not contain much in the way of error-checking; if something goes wrong, you will potentially have to delete a lot of files/symlinks, drop a database and user from MySQL, and try again. Obviously, you should try this out in a test environment before attempting to go into production with it!
  • When running SolrMarc, users may see permission errors related to the default log that SolrMarc tries to create under $VUFIND_HOME/import; these should not prevent indexing from succeeding, but it may be worth investing some time in resolving the error by putting the log in a better place.

Script Code

#!/bin/bash
 
# Script to automatically create a VuFind host-based multisite instance for a particular user
# Creates local database, Solr core, configuration directory, theme and code module
# Developed and tested for Ubuntu 20.04 and VuFind 7.0 (but should work with other versions)
# Check the variable definitions below to make sure paths, database credentials, and naming conventions are correct and appropriate for your needs
# IMPORTANT: after running this script, you will need to restart the Apache and Solr processes for changes to take effect!
 
# Fail if the username was not provided
if [ $# -eq 0 ]; then
  echo "Usage: $0 <username>"
  exit
fi
 
# Set up VuFind and system-specific details we will need...
# VUFIND_HOME = the VuFind home directory
# MYSQL_ROOT_USER = the MySQL root username
# MYSQL_ROOT_PASSWORD = the MySQL root password
# BASE_DOMAIN = the domain for which users will be given subdomains (e.g. if we want username.vufind.org, put vufind.org here)
# APACHE_CONFIG_DIR = the directory where Apache configurations need to be symlinked to be activated
# SOLR_USER = the username of the user that runs the VuFind Solr process
export VUFIND_HOME=/usr/local/vufind
MYSQL_ROOT_USER=root
MYSQL_ROOT_PASSWORD=mypassword
BASE_DOMAIN=localhost
APACHE_CONFIG_DIR=/etc/apache2/conf-enabled
SOLR_USER=solr
 
# Set up variables for username and key user-owned files/directories
USERNAME=$1
USER_HOME=/home/$USERNAME
USER_PROFILE=$USER_HOME/.profile
 
# Set up variables for the user-owned VuFind resources we are going to create
USER_MODULE=VuFind`echo "<?php echo ucwords(strtolower('$USERNAME')) ?>" | php`Module
USER_THEME=user_$USERNAME
USER_VUFIND_DIR=$USER_HOME/vufind
USER_VUFIND_LOCAL_DIR=$USER_VUFIND_DIR/local
USER_DATABASE=vufind_$USERNAME
USER_DATABASE_USER=$USER_DATABASE
USER_DATABASE_PASSWORD=$USER_DATABASE
USER_SOLR_CORE=solr_$USERNAME
USER_HOSTNAME=$USERNAME.$BASE_DOMAIN
 
# Run VuFind installer to create a user-owned VuFind instance
mkdir $USER_VUFIND_DIR
php $VUFIND_HOME/install.php --overridedir=$USER_VUFIND_LOCAL_DIR --module-name=$USER_MODULE --multisite=host --hostname=$USER_HOSTNAME --non-interactive
 
# Set up MySQL database for instance
mysqladmin -u$MYSQL_ROOT_USER -p$MYSQL_ROOT_PASSWORD create $USER_DATABASE
mysql -u$MYSQL_ROOT_USER -p$MYSQL_ROOT_PASSWORD -e "CREATE USER '$USER_DATABASE_USER'@'localhost' IDENTIFIED BY '$USER_DATABASE_PASSWORD'"
mysql -u$MYSQL_ROOT_USER -p$MYSQL_ROOT_PASSWORD -e "GRANT SELECT,INSERT,UPDATE,DELETE ON $USER_DATABASE.* TO '$USER_DATABASE_USER'@'localhost' WITH GRANT OPTION"
mysql -u$MYSQL_ROOT_USER -p$MYSQL_ROOT_PASSWORD -e "FLUSH PRIVILEGES"
mysql -u$MYSQL_ROOT_USER -p$MYSQL_ROOT_PASSWORD -D $USER_DATABASE < $VUFIND_HOME/module/VuFind/sql/mysql.sql
 
# Set up config.ini by using sed to update database details and base URL
mkdir $USER_VUFIND_LOCAL_DIR/config/vufind
sed "s|root@localhost/vufind|$USER_DATABASE_USER:$USER_DATABASE_PASSWORD@localhost/$USER_DATABASE|" < $VUFIND_HOME/config/vufind/config.ini | sed "s|library.myuniversity.edu/vufind|$USER_HOSTNAME/|" > $USER_VUFIND_LOCAL_DIR/config/vufind/config.ini
 
# Add relevant details to user's profile
echo "export VUFIND_HOME=$VUFIND_HOME" >> $USER_PROFILE
echo "export VUFIND_LOCAL_DIR=$USER_VUFIND_LOCAL_DIR" >> $USER_PROFILE
echo "export VUFIND_LOCAL_MODULES=$USER_MODULE" >> $USER_PROFILE
 
# Create a custom theme for the user:
export VUFIND_LOCAL_DIR=$USER_VUFIND_LOCAL_DIR
php $VUFIND_HOME/public/index.php generate theme $USER_THEME
 
# Create a custom Solr core for the user:
mkdir $VUFIND_HOME/solr/vufind/$USER_SOLR_CORE
touch $VUFIND_HOME/solr/vufind/$USER_SOLR_CORE/core.properties
cp -r $VUFIND_HOME/solr/vufind/biblio/conf $VUFIND_HOME/solr/vufind/$USER_SOLR_CORE/conf
sed -i "s/biblio/$USER_SOLR_CORE/" $VUFIND_HOME/solr/vufind/$USER_SOLR_CORE/conf/solrconfig.xml
sed -i "s/biblio/$USER_SOLR_CORE/" $USER_VUFIND_LOCAL_DIR/import/import.properties
sed -i "s/biblio/$USER_SOLR_CORE/" $USER_VUFIND_LOCAL_DIR/import/import_auth.properties
sed -i "s/= biblio/= $USER_SOLR_CORE/" $USER_VUFIND_LOCAL_DIR/config/vufind/config.ini
 
# Set up permissions and symbolic links:
chown -R $USERNAME $USER_VUFIND_DIR
chown -R www-data $USER_VUFIND_LOCAL_DIR/cache
chown -R $USERNAME $USER_VUFIND_LOCAL_DIR/cache/cli
chown -R $USERNAME $VUFIND_HOME/module/$USER_MODULE
ln -s $VUFIND_HOME/module/$USER_MODULE $USER_VUFIND_DIR/$USER_MODULE
chown -R $USERNAME $VUFIND_HOME/themes/$USER_THEME
ln -s $VUFIND_HOME/themes/$USER_THEME $USER_VUFIND_DIR/$USER_THEME
chown -R $SOLR_USER:$USERNAME $VUFIND_HOME/solr/vufind/$USER_SOLR_CORE
chmod -R g+w $VUFIND_HOME/solr/vufind/$USER_SOLR_CORE
ln -s $VUFIND_HOME/solr/vufind/$USER_SOLR_CORE $USER_VUFIND_DIR/$USER_SOLR_CORE
 
# Link up Apache configuration
ln -s $USER_VUFIND_LOCAL_DIR/httpd-vufind.conf $APACHE_CONFIG_DIR/vufind_$USERNAME.conf
installation/installing_multiple_instances/automation_example.txt · Last modified: 2021/07/01 12:27 by demiankatz