====== Starting Solr Automatically in Linux Using the init.d Method ====== :!: Most modern Linux distributions use systemd instead of init.d; please use the [[administration:starting_and_stopping_solr#linux_systemd_method|systemd instructions]] unless you are sure that init.d is a better approach for your situation. :!: Because of the lack of ongoing support for the init.d approach, this documentation is unlikely to be updated or tested in the future. ===== Wrapper Script ===== You can set up Solr to run as a daemon. To do so, create a wrapper script in /etc/init.d/vufind: :!: Important: These instructions were written for VuFind® 3.0 or later, when the Solr script was changed to solr.sh instead of vufind.sh; if running VuFind® 2.x or earlier, you should replace "solr.sh" with "vufind.sh" in these examples. :!: If you need to run VuFind® with non-default settings, you may wish to add some lines to export environment variables in this script, or else source a script containing all of your environment settings prior to running "solr.sh". In many newer installations of VuFind®, such a script is already set up as /etc/profile.d/vufind.sh. :!: Newer versions of Solr do not like to be run by the root user; you may need to either add "export SOLR_ADDITIONAL_START_OPTIONS=-force" to your script to force root permissions, or (preferably) set up your script to run Solr as a [[administration:security#creating_a_dedicated_solr_user|dedicated user]] (which can be done by wrapping the solr.sh command with "/bin/su - username -c ..."). #!/bin/sh ### BEGIN INIT INFO # Provides: vufind # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Description: VuFind® init script ### END INIT INFO cd /usr/local/vufind ./solr.sh $* // Note: The information in the INIT INFO block is only required for RedHat-style systems that use the chkconfig utility. You may need to adjust the start and stop runlevels depending on your system configuration. // // Note: If your VuFind® instance is installed somewhere other than /usr/local/vufind, be sure to adjust the cd line in the script accordingly. // Make sure that the script is executable (sudo may be needed on the command for some platforms): chmod +x /etc/init.d/vufind ===== Runlevel Configuration ===== You will then need to add the script to your runlevel configuration (generally found under /etc/rc.d). The exact setup varies from flavor to flavor of Linux, but a bit of online research should help, as should these tools: On RedHat (including Fedora): chkconfig --add vufind On Debian (including Ubuntu): update-rc.d vufind defaults If this doesn't seem to work, be sure that VUFIND_HOME and JAVA_HOME are set in the profile of the user running the startup script. ===== Interacting with Solr After Automation ===== On some platforms, the "service" command is available to make use of startup scripts. In this case, you will be able to use it for Solr after completing configuration: service vufind start service vufind stop service vufind restart service vufind check //("sudo" may need to be prefixed to these commands depending on your Linux flavor and security configuration)// If service is available, it is the preferred way of starting and stopping Solr after automation.