What's the easiest way to make my old init script work in systemd?
Solution 1:
Seriously, a systemd unit file is trivial to write for a service like this...or for most services.
This ought to get you about 95% of the way there. Put this in, for example, /etc/systemd/system/solr.service
[Unit]
Description=Apache Solr
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
EnvironmentFile=/etc/courtlistener
WorkingDirectory=/usr/local/solr/example
ExecStart=/usr/bin/java -jar -server -Xmx${CL_SOLR_XMX} start.jar -DINSTALL_ROOT=${INSTALL_ROOT}
Restart=on-failure
LimitNOFILE=10000
[Install]
WantedBy=multi-user.target
Note the stuff that isn't here, like the log file and such; systemd will automatically capture and log the service output under the service's name.
Solution 2:
For me it was easier to just add the init info block in the header as suggested here:
#!/bin/sh
### BEGIN INIT INFO
# Provides: solr
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: solr
# Description: solr
### END INIT INFO
Then, execute sudo systemctl enable solr
.
Solution 3:
Another solution to use the solr legacy init script with systemd:
systemctl daemon-reload
systemctl enable solr
systemctl start solr
Solution 4:
It's more convenient to run Solr using provided start script.
The systemd unit file looks like this:
[Unit]
Description=Apache Solr for Nextcloud's nextant app fulltext indexing
After=syslog.target network.target remote-fs.target nss-lookup.target systemd-journald-dev-log.socket
Before=nginx.service
[Service]
Type=forking
User=solr
WorkingDirectory=/path/to/solr/server
ExecStart=/path/to/solr/bin/solr start
ExecStop=/path/to/solr/bin/solr stop
Restart=on-failure
[Install]
WantedBy=multi-user.target
Note that you may also make use of your environment variables by adding EnvironmentFile
to the [Service]
section. The script bin/solr
respects environment variables, just take a look in it.