24
7
Actually I'm not so sure whether i should use Shell Scripts, or if there some ways already. But whatever approach we use, i would like to keep a Service running all the time.
Let's say iptables
as an example. Then ..
- Whenever the
iptables
service isstopped
or (in other words) not running, i want it to bestarted
(orrestarted
) .. automatically whenever it stopped (or not running). - In other more simple words, i want to keep a Service up and running all the time.
(May be i could give a fair frequency to check, if doing Real-time checking is the problem. So lets say, every 5 mins)
The only way i could think of, is to use Shell Scripts with Cron Tab.
- Is there any smart solution please?
Thanks!
You should not do that. Suppose a service is ill-configured, what would your strategy achieve? An infinite list of retrials. You should instead write a crontab script that
alerts
you to something not working. – MariusMatutiae – 2013-12-03T09:12:47.217I'm just curious about the straight solution, for the original question. And also, i have a Service which just needs to be simply
restarted
whenever it stopped, for any reason. No problem with restarting. – 夏期劇場 – 2013-12-03T09:43:59.8371
Your own suggested solution is smart enough. If you use it correctly (exit immediately if service is already running, alert you that the service has stopped so you can fix it, and so on....) it is the simplest way. A service that stops automatically is a problematic service, so eventually you should fix it, but otherwise, as a temporary patch, a cron script or another super-simple daemon that sleeps most of the time will do the job just fine. There are some tools like http://mmonit.com/monit/ but I think that in the end they all use a similar approach
– None – 2013-12-03T10:40:13.267@MariusMatutiae, I agree with your point but it depends on the nature of the service, and most process managers will back off after a number of failed restarts. It's perfectly reasonable for a process to naturally end, and for us to want to restart it automatically, e.g. a worker that picks up a job from a queue and ends after each run. It's also a handy tool for sysadmins that suffer from bespoke memory-leaking code - limit the lifetime of a process and restart it automatically before it can get out of hand... – Alex Forbes – 2013-12-11T23:50:29.343