Benvenuto nella nostra community, registra un account gratuito ADESSO!
Oltre 7000 persone hanno già registrato il loro account. Chiedi aiuto, conversa con aziende ed esperti del settore webhosting italiano.
Iscriviti subito! In meno di 2 minuti!




Risultati da 1 a 11 di 11
  1. #1
    HT Member
    Data Registrazione
    Feb 2006
    Messaggi
    75

    Lightbulb Script per riavviare apache in caso di crash

    L'ho fatto ieri:

    Codice:
    #!/bin/bash
    
    LOG_FILE="/var/log/autorestart-apache_log"
    
    if wget -O /dev/null -o /dev/null localhost
    then
      echo
      echo "`date +%T` `date +%D` - [info]: wget su localhost eseguito correttamente"
      echo
    else
      ERRLOG_MSG="`date +%T` `date +%D` - [errore]: wget su localhost fallito... tentativo di riavvio di httpd"
      echo
      echo $ERRLOG_MSG
      echo $ERRLOG_MSG >> $LOG_FILE
      service httpd restart
      echo
    fi
    
    exit 0
    Lo vorrei utilizzare per riavviare automaticamente apache in caso di crash.

    Non ho molta esperienza di bash script, cosa vi sembra?

    Avete qualche suggerimento per migliorare lo script?

    In particolare c'è un modo migliore per riavviare apache in caso di crash?

    Poi che tempo mi consigliate di inserire nella crontab? Io sono indeciso tra 5 min o 1 min...

    ---

    Ho aggiunto il log dei riavvii...

    ---

    Mi sono accorto ora che forse sarebbe stato meglio postare nel forum "Io Programmo"... in caso Ste o Luca provvedete voi a spostarlo :P
    Ultima modifica di JD82; 06-04-2006 alle 10:18



  2. #2
    /etc/init.d/brain restart L'avatar di Luca
    Data Registrazione
    Feb 2006
    Località
    Bellaria
    Messaggi
    3,271
    spostato

  3. #3
    Appassionato L'avatar di MaxX
    Data Registrazione
    Feb 2006
    Messaggi
    153
    come si usano questi script? come lo inserisco?
    Grazie molte
    Brain load average: 100.00, 110.00, 150.00

  4. #4
    HT Member
    Data Registrazione
    Feb 2006
    Messaggi
    75
    Citazione Originariamente Scritto da MaxX
    come si usano questi script? come lo inserisco?
    Grazie molte
    Ciao MaxX, scusa il ritardo ma sto lottando con apache per un problema di processi impazziti (o almeno credo).

    Lo script lo devi salvare come autorestart-apache.sh (o col nome che ti pare).
    Lo rendi eseguibile (chmod 744 autorestart-apache.sh) poi lo inserisci nella crontab (è lunghetto da spiegare, ma su google trovi tutte le info del caso).

    Ovviamente devi accertarti che il comando service httpd restart funzioni con la tua distro. Questo funziona con le fedora... se non hai fedora al posto di quello devi mettere il comando che restarta apache.

    Cmq questo script l'ho fatto io, e non l'ho ancora testato bene... Sarebbe utile che qualche altra persona che ha familiarita con i bash script ci desse uno sguardo e confermasse che è tutto ok... :P

  5. #5
    /etc/init.d/brain restart L'avatar di Luca
    Data Registrazione
    Feb 2006
    Località
    Bellaria
    Messaggi
    3,271
    girando per il web

    Codice:
     #! /bin/sh
    # /sbin/service
    # Manage System services
    
    service=$1
    act=$2
    export service act
    
    activate () {
            echo $service is now started at boot time
            chmod 755 /etc/rc.d/rc.$service
    }
    
    inactivate () {
            echo $service is now disable at boot time
            chmod 222 /etc/rc.d/rc.$service
    }
    
    test_active () {
            if [ `echo $act | grep "-" | wc -c` -gt 0 ]
                    then
                            inactivate
                    fi
            if [ `echo $act | grep "+" | wc -c` -gt 0 ]
                    then
                            activate
                    fi
    
    }
    
    start (){
            echo 'starting' $service '...'
            chmod 755 /etc/rc.d/rc.$service
            sh /etc/rc.d/rc.$service start
            test_active
    }
    
    stop (){
            echo 'stopping' $service '...'
            chmod 755 /etc/rc.d/rc.$service
            sh /etc/rc.d/rc.$service stop
            test_active
    }
    
    list_active () {
            echo 'active services :'
            ls -l /etc/rc.d/* | grep rwxr-xr-x
    }
    
    list_inactive () {
            echo 'inactive services :'
            ls -l /etc/rc.d/* | grep -v rwxr-xr-x
    }
    
    list_all () {
            if [ `echo $service | wc -c` -gt 1 ]
                    then
                            if [ `ls -l /etc/rc.d/rc.$service | grep rwxr-xr-x | wc -c` -gt 1 ]
                                    then
                                            echo $service 'is active'
                                    else
                                            echo $service 'is not active'
                                    fi
                    else
                            list_inactive
                            list_active
                    fi
    }
    
    apply () {
            case "$act" in
                    *'start')
                            start
                    ;;
                    *'stop')
                            stop
                    ;;
                    *'restart')
                            stop
                            start
                    ;;
                    *)
                            list_all
            esac
    }
    
    usage () {
            echo 'usage : '
            echo '          service ['service'|active|inactive|?] [+|-][start|stop|restart]'
            echo ''
            echo '  where 'service' can be the name of a service'
            echo ''
            echo '  active          : list all actives services on boot'
            echo '  inactive        : list all inactives services on boot'
            echo '  ?               : display this help information'
            echo '  +               : after stopping/starting a service, activate it for auto start at boot time'
            echo '  -               : after stopping/starting a service, unactivate its auto start at boot time'
            echo '  start           : start a service'
            echo '  stop            : stop a service'
            echo '  restart         : restart a service'
            echo ''
            echo '  with just a service name, the command prints if the service is active at boot time or not.'
            echo '  without any argument, the command prints the list of all inactive and actives services.'
    }
    
    case "$1" in
            'active')
                    list_active
            ;;
            'inactive')
                    list_inactive
            ;;
            '?')
                    usage
            ;;
            *)
                    apply
    esac
    
    
    exit 0
    non ci ho guardato bene... e ora non ho la mente pronta per provarlo
    Ultima modifica di Luca; 07-04-2006 alle 23:41

  6. #6
    HT Member
    Data Registrazione
    Feb 2006
    Messaggi
    75
    Ehm... quindi?

    ---

    Mi sembra lo script che permette di scrivere "service httpd restart" per riavviare apache.

    Ma lo script che ho fatto io riavvia apache da solo quando il wget fallisce...
    E utilizza lo script che hai trovato per riavviarlo...

  7. #7
    /etc/init.d/brain restart L'avatar di Luca
    Data Registrazione
    Feb 2006
    Località
    Bellaria
    Messaggi
    3,271
    Citazione Originariamente Scritto da JD82
    Ehm... quindi?
    è l'alternativa

  8. #8
    HT Member
    Data Registrazione
    Feb 2006
    Messaggi
    75
    mmm, non so se è un'alternativa...
    in che modo lo potresti usare per riavviare apache in caso di crash? solo abbinato ad uno script simile a quello che ho fatto io, no?
    (casualmente l'ho usato senza saperlo )

  9. #9
    /etc/init.d/brain restart L'avatar di Luca
    Data Registrazione
    Feb 2006
    Località
    Bellaria
    Messaggi
    3,271
    sinceramente non ho neache guardo il code...
    Sono troppo cotto...

  10. #10
    HT Member
    Data Registrazione
    Feb 2006
    Messaggi
    75

    Io uno sguardo ce l'ho dato, e se non erro è lo script che ti permette di scrivere in console service nome_servizio restart|stop|start per riavviare|fermare|avviare un servizio.

    Se non è lui, ha la sintassi uguale :
    Codice:
    usage () {
            echo 'usage : '
            echo '          service ['service'|active|inactive|?] [+|-][start|stop|restart]'
            echo ''
            echo '  where 'service' can be the name of a service'
            echo ''
            echo '  active          : list all actives services on boot'
            echo '  inactive        : list all inactives services on boot'
            echo '  ?               : display this help information'
            echo '  +               : after stopping/starting a service, activate it for auto start at boot time'
            echo '  -               : after stopping/starting a service, unactivate its auto start at boot time'
            echo '  start           : start a service'
            echo '  stop            : stop a service'
            echo '  restart         : restart a service'
            echo ''
            echo '  with just a service name, the command prints if the service is active at boot time or not.'
            echo '  without any argument, the command prints the list of all inactive and actives services.'
    e io l'ho utilizzato per riavviare apache in caso fallisce la wget:
    Codice:
    else
      ERRLOG_MSG="`date +%T` `date +%D` - [errore]: wget su localhost fallito... tentativo di riavvio di httpd"
      echo
      echo $ERRLOG_MSG
      echo $ERRLOG_MSG >> $LOG_FILE
      service httpd restart
      echo
    
    fi

  11. #11
    HTastinator L'avatar di gipo
    Data Registrazione
    Sep 2007
    Messaggi
    426

    Re: Script per riavviare apache in caso di crash

    Ciao JD82,

    sto provando il tuo script ma mi sa che non funziona.... a te va?
    Dedicato e VPS Linux Debian - “Linux for human beings”

    Gipo

Discussioni Simili

  1. Amazon, non riavviare quel server!
    Di Redazione HostingTalk nel forum Articoli e news su Webhosting e Servizi Internet
    Risposte: 0
    Ultimo Messaggio: 09-12-2011, 16:11
  2. installare patch SENZA riavviare - mito o realtà ?
    Di WizOfOz nel forum Gestione Server Windows e Server Linux
    Risposte: 7
    Ultimo Messaggio: 14-02-2010, 22:19
  3. Crash apache
    Di TheDarkITA nel forum Gestione Server Windows e Server Linux
    Risposte: 8
    Ultimo Messaggio: 03-03-2008, 16:45
  4. Crash del VPS inspiegabile.
    Di pchs nel forum VPS - Virtual Private Server
    Risposte: 17
    Ultimo Messaggio: 18-03-2007, 10:38
  5. Script per riavviare apache in caso di crash
    Di JD82 nel forum VPS - Virtual Private Server
    Risposte: 0
    Ultimo Messaggio: 06-04-2006, 10:07

Informazioni Discussione

Utenti che Stanno Visualizzando Questa Discussione

Ci sono attualmente 1 utenti che stanno visualizzando questa discussione. (0 utenti e 1 ospiti)

Tag per Questa Discussione

Segnalibri

Permessi di Scrittura

  • Tu non puoi inviare nuove discussioni
  • Tu non puoi inviare risposte
  • Tu non puoi inviare allegati
  • Tu non puoi modificare i tuoi messaggi
  •