Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
systemd service file for Apache SOLR
# put this file in /etc/systemd/system/ as root
# below paths assume solr installed in /opt/solr, SOLR_PID_DIR is /data
# and that all configuration exists in /etc/default/solr.in.sh which is the case if previously installed as an init.d service
# change port in pid file if differs
# note that it is configured to auto restart solr if it fails (Restart=on-faliure) and that's the motivation indeed :)
# to switch from systemv (init.d) to systemd, do the following after creating this file:
# sudo systemctl daemon-reload
# sudo service solr stop # if already running
# sudo systemctl enable solr
# systemctl start solr
# this was inspired by https://confluence.t5.fi/display/~stefan.roos/2015/04/01/Creating+systemd+unit+(service)+for+Apache+Solr
[Unit]
Description=Apache SOLR
After=syslog.target network.target remote-fs.target nss-lookup.target systemd-journald-dev-log.socket
Before=multi-user.target graphical.target nginx.service
Conflicts=shutdown.target
[Service]
User=solr
PIDFile=/data/solr-8983.pid
Environment=SOLR_INCLUDE=/etc/default/solr.in.sh
ExecStart=/opt/solr/bin/solr start
ExecStop=/opt/solr/bin/solr stop
Restart=on-failure
[Install]
WantedBy=multi-user.target graphical.target
@hammady

This comment has been minimized.

Copy link
Owner Author

@hammady hammady commented Jan 9, 2017

Note that it delays nginx.service in case it is used as reverse proxy for the solr upstream

@gadelkareem

This comment has been minimized.

Copy link

@gadelkareem gadelkareem commented Apr 28, 2018

seems like Restart=on-failure makes Solr restart forever. Did it work for you?

@wryfi

This comment has been minimized.

Copy link

@wryfi wryfi commented Jan 24, 2019

Note you will probably need to add the following in your [Service] stanza:

LimitNOFILE=65000
LimitNPROC=65000
@mhitza

This comment has been minimized.

Copy link

@mhitza mhitza commented Apr 16, 2020

If anyone else drops by looking for an updated service file, here is my definition and my rationale http://archive.vn/ld10Q#selection-135.2887-135.3889

[Unit]
Description=Apache SOLR

[Service]
Type=forking
User=solr
Environment=SOLR_INCLUDE=/etc/default/solr.in.sh
ExecStart=/opt/solr/bin/solr start
ExecStop=/opt/solr/bin/solr stop
Restart=on-failure
LimitNOFILE=65000
LimitNPROC=65000
TimeoutSec=180s

[Install]
WantedBy=multi-user.target

Props to @wryfi for the limit definitions, TIL

@igorbga

This comment has been minimized.

Copy link

@igorbga igorbga commented Nov 5, 2021

Thanks @mhitza , works great in Debian 11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment