autostart script for stopped services


 
Thread Tools Search this Thread
Top Forums Programming autostart script for stopped services
# 1  
Old 09-13-2011
autostart script for stopped services

I need script that to start the stopped service when its stopped.
This script always controls status of service. For example nagios service stopped script have to start nagios service. And It can send an email for notification when stopped.
# 2  
Old 09-13-2011
What OS is this? Some OSes - like Solaris - have special commands for controlling services.
# 3  
Old 09-13-2011
I think it be some cross platform way
PHP Code:
#!/usr/bin/perl

use strict;
use 
warnings;
use 
Proc::Daemon;

Proc::Daemon::Init;

my $continue 1;
$SIG{TERM} = sub $continue };

while (
$continue) {
     
#do stuff

# 4  
Old 09-14-2011
I need this script for redhat. But I can use for Solaris. Everybody can use this script.

What is the special command for controlling the service for Solaris.

How can I use below script for ntop service.
Code:
# pgrep ntop
17551
#

PHP Code:
#!/usr/bin/perl

use strict;
use 
warnings;
use 
Proc::Daemon;

Proc::Daemon::Init;

my $continue 1;
$SIG{TERM} = sub $continue };

while (
$continue) {
     
#do stuff

# 5  
Old 09-14-2011
Special command Solaris: svcadm

Once you add the service to known services, then svcadm enable will run, and keep restarting the service automatically. Forever.
# 6  
Old 09-15-2011
svcadm is not autostart the service when stopped.
# 7  
Old 09-22-2011
Finally, I did my script for nagios and ntop services.

FOR NAGIOS

***** crontab *****
Code:
[root@GateWay /]# crontab -l
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
@reboot ./autostart.sh > /tmp/autostart.log 2>&1 
[root@GateWay /]#

***** autostart.sh ****** root(/)

Code:
[root@GateWay /]# cat autostart.sh 
#!/usr/bin/env bash
#export ARGELA_RUN_HOME=/
nagios_kontrol()
{
#    hOldPID=0
    while :; do
      hPID=0
        hPID=`pgrep -f '/usr/bin/nagios -d /etc/nagios/nagios.cf'`

      if [ -z "$hPID" ] ; then
          if [ -f $ARGELA_RUN_HOME/sbin/service ]; then
            $ARGELA_RUN_HOME/sbin/service nagios start
          else
            echo "############################################"
            echo "###      Can not find nagios service     ###"
            echo "###      Check ARGELA_RUN_HOME setting   ###"
            echo "###      Execution failed...             ###"
            echo "############################################"
            break
          fi
      else
        sleep 10
      fi
    done
}
nagios_kontrol & 


[root@GateWay /]#

*********root***************
.autostart.sh
/tmp/autostart.log // for logging


FOR NTOP

***** crontab *****

Code:
[root@argela /]# crontab -l
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
@reboot ./autostart.sh > /tmp/autostart.log 2>&1

[root@argela /]#

***** autostart.sh ****** root(/)

Code:
[root@argela /]# cat autostart.sh 
#!/usr/bin/env bash
#export ARGELA_RUN_HOME=/
ntop_kontrol()
{
#    hOldPID=0
    while :; do
      hPID=0
        hPID=`pgrep -f 'ntop'`

      if [ -z "$hPID" ] ; then
          if [ -f $ARGELA_RUN_HOME/./autostart_ntop.sh ]; then
            $ARGELA_RUN_HOME/./autostart_ntop.sh
          else
            echo "############################################"
            echo "### Can not find ntop for executable      ###"
            echo "###      Check NTOP please                ###"
            echo "###       Execution failed...             ###"
            echo "############################################"
            break
          fi
      else
        sleep 10
      fi
    done
}
ntop_kontrol & 


[root@argela /]#

***** autostart_ntop.sh ****** root(/)

Code:
[root@argela /]# cat autostart_ntop.sh 
/usr/local/bin/ntop  -d -i "eth0" -L -P /usr/local/var/ntop -u ntop --skip-version-check  --use-syslog=daemon > /tmp/autostart_ntop.log 2>&1
[root@argela /]#

*********root***************
autostart.sh and autostart_ntop.sh
/tmp/autostart_ntop.log // for logging

Last edited by pludi; 09-22-2011 at 09:21 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn Shell script in stopped state while running in background

Hi, I want to run a shell script in background . but its going to stopped state $ ksh cat_Duplicate_Records_Removal.ksh & 8975 $ + Stopped (tty output) ksh cat_Duplicate_Records_Removal.ksh & why is this happening? Also could anyone please tell me what is a stopped... (12 Replies)
Discussion started by: TomG
12 Replies

2. Shell Programming and Scripting

Perl script stopped working

Hi, I have the following segment of a script which is supposed to prompt a user for password and then capture the password entered by the user. The function is called in by another script and used to work without issue, the problem is that recently the script is not waiting for the user to... (3 Replies)
Discussion started by: belalr
3 Replies

3. Shell Programming and Scripting

Script to Start services based on dependent services on other AIX machine

Hi, I just started working on a script. After my research, i found a command which can help me: AIM: To build a script which starts the services (Services 1) on server 1 automatically whenever its down. And it has a dependency on other service (Service 2) on Server 2. So my script has to... (4 Replies)
Discussion started by: draghun9
4 Replies

4. Shell Programming and Scripting

shell script getting stopped at the middle.

I have created a shell scrit to run the informatica workflows sequentially.In the script i am executing 7 workflows sequentially after running 4 workflows the scrpt getting stop and it is not continuing next step evn it is updating logs.4th workflow will take more time to finish is that making... (1 Reply)
Discussion started by: katakamvivek
1 Replies

5. UNIX for Advanced & Expert Users

stopped(sigttou) error while executing a script in background

Hi All, I have an issue where in when i execute a script in the background using '&', it exits with stopped(SIGTTOU) signal. There are two servers, where the Compute server is HP-Unix and Data server is Linux. I tried using the "stty - tostop" command to disable the SIGTTOU for background... (1 Reply)
Discussion started by: vmenon
1 Replies

6. Debian

Iomega ix2-200 Custom Debian - Autostart script in init.d not Working

!!Hello Everyone!! I Recently purchased a Iomega iX2-200 NAS that runs a custom debian installed by Iomega (Linux Debian 5.0.2 ( 2.6.22.18 armv5tejl)) . I have SSH access. I installed Transmission since the factory installed torrents manager that Iomega uses is terrible. Transmission-daemon... (1 Reply)
Discussion started by: stejimenez
1 Replies

7. AIX

Autostart of LPAR

Hi, I have 2 lpars on my AIX that needs to be started manually after each reboot. Because the servers are storing the NFS and NIS info, other servers won't run correctly until they start up. I found in IBM documentation the steps to make it automatic. My question is, I want to know if... (2 Replies)
Discussion started by: rahzzbietel
2 Replies

8. Shell Programming and Scripting

why my script stopped- any reason(urgent please)

Hi Friends, iam running some scripts, which are all off suddenly stopping. Can any one tell me the reason why it happend. Is there any reason to stop the scripts. Thanks Krishna. (1 Reply)
Discussion started by: krishna9
1 Replies

9. UNIX and Linux Applications

Autostart/Autorun Applications

I have developed a CD that runs both Windows and Mac software. I would like it to function as an autorun/autostart; I do not have a problem with the Windows code, but I do for the Mac. I do not feel like investing a couple of hundred $$$ into software, when, I am sure that several lines of UNIX... (2 Replies)
Discussion started by: HornetDr
2 Replies

10. HP-UX

rc.log problem about autostart script

On HP-UX, we add some our autostart scripts in the system script under /sbin/rc*.d directory. The output of application is redirected to /dev/null in our script,but once the application has been startup with the OS starting,its ouput is redirected to the /etc/rc.log finally and cause the rc.log... (2 Replies)
Discussion started by: Frank2004
2 Replies
Login or Register to Ask a Question