Installing eZ Find's Solr on CentOS 7
To set up Apache Solr -- the search platform that powers eZ Publish (through the eZ Find extension) and eZ Platform -- as a service on CentOS 7, you have at least two options. We’ll cover both: a manually created service for the new systemd as well as the older SystemV -- via the service script included with eZ Find.
What is systemd?
CentOS 7 features a new way of loading service scripts via systemd, which takes some getting used to for those coming from earlier versions of CentOS.
A very TLDR summary about systemd:
“systemd is an init system used in Linux distributions to bootstrap the user space and manage all subsequent processes, instead of the UNIX System V or Berkeley Software Distribution (BSD) init systems. ... One of systemd's main goals is to unify basic Linux configurations and service behaviors across all distributions.” 
systemd service setup
To set up a systemd service we’ll create a new service file.
$ sudo vi /etc/systemd/system/solr.service [Unit] Description=Apache SOLR After=syslog.target network.target remote-fs.target nss-lookup.target [Service] WorkingDirectory=/var/www/ezpublish_legacy/extension/ezfind/java PIDFile=solr.pid User=root ExecStart=/usr/bin/java -Dezfind -jar start.jar ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
Starting, restarting, and stopping the service is handled via systemctl.
(Adding .service to the lines below is optional as systemctl will automatically look for it)
$ sudo systemctl start solr.service $ sudo systemctl restart solr.service $ sudo systemctl stop solr.service
Since systemctl doesn't give you feedback by default, run a status check to see if the service is working as expected.
$ sudo systemctl status solr.service
If the service is working as expected, the service can be enabled to start at boot.
$ sudo systemctl enable solr.service
Breaking it down
The [Unit] section
The Description setting is used to describe the service as well as its functionality. Being specific here will help to identify the service and its function down the track.
A number of systemd tools display this information.
The After setting defines the units that will be started before this unit. Units listed here are not dependencies. If dependencies are required, use the Requires or Wants settings.
The [Section] section
This section contains the service configuration. A service section should contain a Type setting, which controls how systemd handles this service.
If no Type or BusName setting are supplied, the service type defaults to ‘simple’, which means systemd considers the service to be started immediately. The main process of the service needs to be defined via ExecStart in that case.
- WorkingDirectory where the service's executable is located
- PIDFile the service’s process id file location
- User the user to run the service
- ExecStart the command to run to start the service
- ExecReload the command to run to reload the service
- ExecStop the command to run to stop the service
- PrivateTmp specifies the use of a private /tmp directory
The [Install] section
WantedBy specifies how the service unit should be enabled. The setting is not used by systemd at runtime, but when the service is enabled or disabled via systemctl.
A symlink is created in /etc/systemd/system/<wanted_by_value>.wants/<symlink_to_unit> creating a dependency so that the current units starts when the listed unit does.
The systemd target multiuser.target is equivalent to the SystemV runlevels 2,3,4 (Set up a non-graphical multi-user system)
SystemV service setup
While loading service scripts via systemd is new to CentOS 7, it still has legacy support for SystemV.
eZ Find includes service scripts for Debian, Gentoo, and RHEL out of the box.
We will use the RHEL script, following the instructions found at the top of the file located in <ezp_root>/extensions/ezfind/bin/scripts/rhel/solr.sh
$ vi <ezp_root>/extensions/ezfind/bin/scripts/rhel/solr.sh ... # chkconfig: 2345 64 36 # description: SOLR indexing server # processname: solr # pidfile: /var/run/solr.pid DESC="Solr indexing server" NAME=solr SOLR_HOME=/var/www/ezpublish_legacy/extension/ezfind/java # Set solr home here JAVA_HOME= # Set java home here if java is not available in /usr/bin/java or /usr/local/bin/java ...
- Set the correct SOLR_HOME value (the java folder of your ezfind extension)
- Set the correct JAVA_HOME value
- Copy the file to /etc/init.d
- Make the service script executable e.g. chmod +x
- Run chkconfig --add solr
To check if your service was set up successfully, use chkconfig.
$ sudo chkconfig ... network 0:off 1:off 2:on 3:on 4:on 5:on 6:off solr 0:off 1:off 2:on 3:on 4:on 5:on 6:off
You can also check the service status via systemctl.
$ sudo systemctl status solr ... solr.service - SYSV: SOLR indexing server Loaded: loaded (/etc/rc.d/init.d/solr; vendor preset: disabled) Active: active (running) since Mon 2017-02-20 05:10:32 UTC; 2 months 23 days ago Docs: man:systemd-sysv-generator(8) Main PID: 3271 (java) ...
To update the service description and name, change the values for DESC and NAME in the service script.
If you update those values, also update the chkconfig settings lines above it.
The first line of the chkconfig settings defines the run-levels and can be left as is.
Note: Also leave the # characters at the beginning of each line in place.
... # description: SOLR indexing server (MyNameHere) # processname: solr-mynamehere # pidfile: /var/run/solr-mynamehere.pid
Links and sources
Commentsblog comments powered by Disqus
Hi, we're Mugo Web - Nice to meet you!
We're a group of web experts who solve complex web problems.Learn more about us »
- Business solutions (48)
- Case study (19)
- eZ Publish add-ons (21)
- eZ Publish community (10)
- eZ Publish development tips (60)
- Productivity tools (6)
- Site performance (10)
- User experience (26)
- Web accessibility (14)
- Web solutions (45)
- Work at Mugo (7)
Yes - we can do that.
Many years of experience with complex websites allows us to offer total solutions.Learn more about what we can do »
We love our clients (and they love us too)
We've solved problems across North America and around the world.Learn more about what we've done »
We tweet too
Follow us on Twitter for the latest Mugo happenings