Automatically start a program (Sphinx searchd) when server is restarted?

2

0

When my server (running CENTOS) is restarted I have to manually start searchd for each website I use Sphinx on.

It's not hard to do (just copy/paste one line in the terminal for each site), but if I forget to do it, or am not aware that the server has been restarted, then search will be down on my websites.

The command I'm referring to to start searchd is this:

/usr/local/bin/searchd --config /path/to/sphinx/etc/sphinx.conf

Is there a way to have searchd automatically start up when my server is restarted?

Nate

Posted 2014-09-10T21:33:55.787

Reputation: 1 125

1Modify the apache start/stop scripts to also start/stop sphinx? – ssnobody – 2014-09-11T01:55:47.787

searchd is part of Sphinx, not of Apache, so is a separate service. You shouldn't need to restart it when restarting Apache. To ensure that the service is running, add rather your above command to /etc/rc.local. – harrymc – 2015-01-09T18:29:12.550

1@harrymc I think you are right. I'm changing my question. – Nate – 2015-01-09T20:46:51.620

What version of CentOS are you using? This is important to know because CentOS 7 uses systemd for system startup. – FSMaxB – 2015-01-16T14:49:45.603

@FSMaxB I have version 6.6 – Nate – 2015-01-16T16:37:42.820

Answers

2

To configure Sphinx to start automatically, start by adding the searchd start command to the server rc.local file :

sudo vim /etc/rc.local

Paste the following code just above the exit 0 line :

/usr/bin/searchd --config /var/www/yoursitecom/sphinx/etc/sphinx.conf

Now that everything is setup and running, to make sure that the index stays up-to-date with the database, run a crontab to rotate (rebuild) the index every 6 hours :

sudo crontab -e

Add the following line to the bottom of the document.

0 */6 * * * /usr/bin/indexer --rotate --config /var/www/yoursitecom/sphinx/etc/sphinx.conf --all

Source : Working with Sphinx (Search Engine) on a LAMP (Linux, Apache, MySQL, and PHP) Stack Server.

harrymc

Posted 2014-09-10T21:33:55.787

Reputation: 306 093

6

in my case (Debian 8.9)

  /usr/bin/searchd --config /etc/sphinxsearch/sphinx.conf 

does not start sphinx and instead I need to run

  sudo service sphinxsearch start

to get sphinx started

The answer from harrymc pointed me to the right solution and when I edited

  sudo nano /etc/rc.local

and included

  sudo service sphinxsearch start 

just before the exit 0 line, then it finally loaded sphinx upon reboot.

João Martins

Posted 2014-09-10T21:33:55.787

Reputation: 131

0

You may also consider using something like supervisor. It is not as simple as using /etc/rc.local and it require some configuration but it gives more flexibility.

dtoubelis

Posted 2014-09-10T21:33:55.787

Reputation: 136

-1

In my case works this:

in /etc/rc.local

I added line: service searchd start

Tomas

Posted 2014-09-10T21:33:55.787

Reputation: 1