Script au démarrage/fermeture pour onduleur

Bonjour à tous (c’est mon tout premier post^^ :smiley:),

Je cherche à insérer 2 scripts en vue de finaliser la configuration d’un UPS belkin mais étant tout juste débutant avec debian je ne sais pas où les mettre exactement, ces 2 scripts sont issus de cette doc

pour le script de démarrage il est écrit :

et pour le script à la fermeture :

Pour le script de fermeture je crois qu’il s’agit de l’insérer à la fin du fichier /etc/init.d/halt. ?? mais j’en suis pas sûr. Quand au script de démarrage là je vois pas. :frowning:

C’est dans /etc/init.d qu’i faut mettre ce genre de scripts.

burp:/etc/init.d# pwd /etc/init.d burp:/etc/init.d# ls alsa dbus-1 hotplug-net makedev nviboot scsitools-pre.sh udev-mtab apache dirmngr hwclockfirst.sh module-init-tools portmap scsitools.sh umountfs atd discover hwclock.sh modutils ppp sendsigs umountnfs.sh bootclean.sh dns-clean hwtools mountall.sh pppd-dns single urandom bootlogd exim4 ifupdown mountnfs.sh procps.sh skeleton xdebconfigurator bootmisc.sh fam ifupdown-clean mountvirtfs rc ssh xfree86-common checkfs.sh gdm inetd netatalk rcS stop-bootlogd xprint checkroot.sh halt initrd-tools.sh networking README sudo console-screen.sh hdparm kdm nfs-common reboot sysklogd cron hostname.sh keymap.sh nfs-kernel-server rmnologin sysstat cupsys hotplug klogd ntpdate samba udev

Ensuite, tu fais les liens correspondants dans les répertoires rc:

burp:/etc/init.d# ls -ld /etc/rc*
drwxr-xr-x  2 root root 4096 2006-03-05 14:06 ../rc0.d
drwxr-xr-x  2 root root 4096 2006-03-05 14:06 ../rc1.d
drwxr-xr-x  2 root root 4096 2006-03-05 14:06 ../rc2.d
drwxr-xr-x  2 root root 4096 2006-03-05 14:06 ../rc3.d
drwxr-xr-x  2 root root 4096 2006-03-05 14:06 ../rc4.d
drwxr-xr-x  2 root root 4096 2006-03-05 14:06 ../rc5.d
drwxr-xr-x  2 root root 4096 2006-03-05 14:06 ../rc6.d
drwxr-xr-x  2 root root 4096 2006-04-17 18:19 ../rcS.d
burp:/etc/init.d#

Le contenu de ces répertoires, c’est simplement des liens sur le contenu de /etc/init.d
Par exemple:

burp:/etc/rc2.d# ls -l total 0 lrwxrwxrwx 1 root root 18 2005-12-20 16:38 S10sysklogd -> ../init.d/sysklogd lrwxrwxrwx 1 root root 15 2005-12-20 16:38 S11klogd -> ../init.d/klogd lrwxrwxrwx 1 root root 14 2005-12-20 19:01 S12alsa -> ../init.d/alsa lrwxrwxrwx 1 root root 13 2005-12-20 16:38 S14ppp -> ../init.d/ppp lrwxrwxrwx 1 root root 17 2005-12-20 18:04 S18portmap -> ../init.d/portmap lrwxrwxrwx 1 root root 16 2005-12-20 18:05 S20cupsys -> ../init.d/cupsys lrwxrwxrwx 1 root root 16 2005-12-20 18:04 S20dbus-1 -> ../init.d/dbus-1 lrwxrwxrwx 1 root root 17 2005-12-20 18:04 S20dirmngr -> ../init.d/dirmngr lrwxrwxrwx 1 root root 15 2005-12-20 16:38 S20exim4 -> ../init.d/exim4 lrwxrwxrwx 1 root root 15 2005-12-20 16:38 S20inetd -> ../init.d/inetd lrwxrwxrwx 1 root root 17 2005-12-20 16:38 S20makedev -> ../init.d/makedev lrwxrwxrwx 1 root root 27 2005-12-20 18:04 S20nfs-kernel-server -> ../init.d/nfs-kernel-server lrwxrwxrwx 1 root root 15 2005-12-20 18:04 S20samba -> ../init.d/samba lrwxrwxrwx 1 root root 13 2005-12-20 18:04 S20ssh -> ../init.d/ssh lrwxrwxrwx 1 root root 17 2005-12-23 20:14 S20sysstat -> ../init.d/sysstat lrwxrwxrwx 1 root root 26 2005-12-20 21:17 S20xdebconfigurator -> ../init.d/xdebconfigurator lrwxrwxrwx 1 root root 16 2005-12-20 18:53 S20xprint -> ../init.d/xprint lrwxrwxrwx 1 root root 13 2005-12-20 18:04 S21fam -> ../init.d/fam lrwxrwxrwx 1 root root 20 2005-12-20 18:04 S21nfs-common -> ../init.d/nfs-common lrwxrwxrwx 1 root root 13 2005-12-20 16:38 S89atd -> ../init.d/atd lrwxrwxrwx 1 root root 14 2005-12-20 16:38 S89cron -> ../init.d/cron lrwxrwxrwx 1 root root 16 2005-12-24 16:48 S91apache -> ../init.d/apache lrwxrwxrwx 1 root root 13 2005-12-20 18:06 S99gdm -> ../init.d/gdm lrwxrwxrwx 1 root root 13 2006-03-05 14:06 S99kdm -> ../init.d/kdm lrwxrwxrwx 1 root root 19 2005-12-20 16:38 S99rmnologin -> ../init.d/rmnologin lrwxrwxrwx 1 root root 23 2005-12-20 16:38 S99stop-bootlogd -> ../init.d/stop-bootlogd burp:/etc/rc2.d#

Pour faire les chose proprement, il faut utiiliser update-rc.d
Regardes la man page de update-rc.d, c’est très bien expliqué.

NON ! C’est une très mauvaise idée, on ne modifie en principe jamais les scripts standards du système.
Il faut créer tes propres scripts et les placer dans /etc/init.d et ensuite, comme je l’ai dit plus haut utiliser update-rc.d pour créer les liens correspondant.

Extrait de la man page:

[quote]NOM
update-rc.d - Pour installer ou supprimer les liens vers les scripts d’ initialisation de type System-V

SYNOPSIS
update-rc.d [-n] [-f] nom remove

   update-rc.d [-n] nom defaults [NN | NN-start NN-stop]

   update-rc.d [-n] nom start|stop NN runlevel runlevel ...  .  start|stop NN runlevel runlevel ...  .[/quote]

merci pour ces précisions jabba. Après avoir fait pas mal de recherches j’ai réussi à trouver des places pour ces 2 scripts:

-le script pour la fermeture qui contient :

# if shutdown was caused by UPS, perform Belkin UPS workaround.
if [ -f /etc/killpower ] ; then
    echo "Waiting for AC power, or for UPS batteries to run out..."
    belkinunv -x wait /dev/ttyS0

    # we get here if the power came back on. Reboot.
    echo "Power is back. Rebooting..."
    reboot
fi

j’ai créer un lien en /etc/rc0d/S89ups-wait.sh (après le script umountall et avant halt)

-le script pour au démarrage qui contient :

# if we are recovering from a power failure, wait for the UPS to
# charge to a comfortable level before writing anything to disk
if [ -f /etc/killpower ] ; then
    echo "Waiting for UPS battery charge to reach 60%..."
    belkinunv -x wait=60 -x nohang /dev/ttyS0
fi

j’ai créer un lien en /etc/rcSd/S01ups-recharge.sh (c’est donc le premier script exécuté)

j’ai dû mettre le fichier belkinunv en /bin, maintenant tout fonctionne.:smiley: