I have a program that I added to /etc/rc.local to have it run as soon as the server starts. The problem is that sometimes the program stops responding and I need to restart it but I can not restart the server. I can only restart the server at night but the program sometimes dies during the day.
3 Answers
Instead of putting it in rc.local
directly, the "proper" way to do it is to put a script in /etc/init.d
that will respond to 'start|stop|restart' to do the right things to the program's process, then have the system symlink it into the rc directories via update-rc.d scriptname defaults
.
Then, use service scriptname restart
to restart it.
As mentioned by Shane you'll want to create an init script to start/stop/restart the service. As far as the program not responding, you'll want to find the root cause of that first. You can also use GOD http://god.rubyforge.org/ to monitor and automatically restart the program (using your rc.local entry)
Hope that helps.
It is possible Ubuntu already has such a facility built-in via the standard rc system, but you might Google around "ubuntu daemon health monitor" and the like. I found a program called monit which you could probably install and configure to check in on your process and restart it when it fails.
/etc/ini.d/whatever start
might do it.