LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Restart a service automatically (https://www.linuxquestions.org/questions/linux-newbie-8/restart-a-service-automatically-667470/)

rushenas 09-04-2008 02:01 AM

Restart a service automatically
 
Hi all
I wanna know, is there a way to restart a service automatically when sth killed it's related process? E.G, consider that I wanna have my vsftpd always running, and if something stopped it, Linux start it again automatically.

henry_shadowjet 09-04-2008 02:27 AM

Your best bet is to run a script that checks for the processes and put it in the crontab to run and check every few minutes (depending on the needs).

I'm thinking somewhere like "ps -e" and testing whether the service is active.

If you use Fedora, you can also use /sbin/service <servicename> status to show the status of the service.

There are different ways to do this, but I can't write the script for you right now, sorry. But I'm sure there are plenty of guys here who can ^^

jschiwal 09-04-2008 03:05 AM

If the service is controlled by xinetd, then another instance is started each time a new connection if made. Check how vsftp is run.

It may be started normally in runlevels 3 and 5 but have an /etc/xinetd.d/vsftpd configuration file as well.

If so, you could run "sudo /sbin/chkconfig vsftpd off" and then "sudo /sbin/chkconfig vsftpd xinetd".
The second entry will simply delete the "disable = yes" line which you could do yourself.
Code:

# default: off
# description:
#  The vsftpd FTP server serves FTP connections. It uses
#  normal, unencrypted usernames and passwords for authentication.
# vsftpd is designed to be secure.
#
# NOTE: This file contains the configuration for xinetd to start vsftpd.
#      the configuration file for vsftp itself is in /etc/vsftpd.conf
#
service ftp
{
        socket_type            = stream
        protocol                = tcp
        wait                    = no
        user                    = root
        server                  = /usr/sbin/vsftpd
#        server_args            =
#        log_on_success          += DURATION USERID
#        log_on_failure          += USERID
#        nice                    = 10
}



All times are GMT -5. The time now is 04:22 PM.