10. Application sur init

10.1. Application

10.1.1. Première partie

  1. Regarder dans quel niveau d'init est lancé con (inetd n'étant pas installé)

    vanvincq@Debian-Laptop /etc $ ls -l rc* | grep --color -E 'rc|/cron'
    
    -rwxr-xr-x 1 root root  306 24 mars   2011 rc.local
    rc0.d:
    rc1.d:
    rc2.d:
    lrwxrwxrwx 1 root root  14 24 janv. 21:14 S21cron -> ../init.d/cron
    lrwxrwxrwx 1 root root  18 24 janv. 21:14 S25rc.local -> ../init.d/rc.local
    rc3.d:
    lrwxrwxrwx 1 root root  14 24 janv. 21:14 S21cron -> ../init.d/cron
    lrwxrwxrwx 1 root root  18 24 janv. 21:14 S25rc.local -> ../init.d/rc.local
    rc4.d:
    lrwxrwxrwx 1 root root  14 24 janv. 21:14 S21cron -> ../init.d/cron
    lrwxrwxrwx 1 root root  18 24 janv. 21:14 S25rc.local -> ../init.d/rc.local
    rc5.d:
    lrwxrwxrwx 1 root root  14 24 janv. 21:14 S21cron -> ../init.d/cron
    lrwxrwxrwx 1 root root  18 24 janv. 21:14 S25rc.local -> ../init.d/rc.local
    rc6.d:
    rcS.d:
    
  2. Désactivation cron dans tous les niveaux.

    vanvincq@Debian-Laptop ~ $ update-rc.d -f cron remove
    
  3. Restauration du service dans l'état initial

    vanvincq@Debian-Laptop ~ $ update-rc.d cron defaults
    

10.1.2. Deuxième partie

Copie du script dummy.sh dans /usr/sbin

vanvincq@Debian-Laptop ~ $ cp -i ./dummy.sh /usr/sbin/

Copie du script dummyd.sh dans /etc/init.d

vanvincq@Debian-Laptop ~ $ cp -i ./dummyd.sh /etc/init.d
vanvincq@Debian-Laptop ~ $ cat /usr/sbin/dummy.sh
#!/bin/sh

varrun=/var/run
file=dummy

while true ;do
	mkdir -p ${varrun}/${file}
	#On stocke le N° de PID du service dans un fichier
	echo $$ > ${varrun}/${file}/${file}.pid ;read ;
done
vanvincq@Debian-Laptop ~ $ cat /etc/init.d/dummyd.sh
#!/bin/sh

varrun=/var/run
file=dummy
repwork=/etc/init.d
logdir=/tmp/log

  case "$1" in
     start)
     # On journalise le lancement du serveur
	if [ ! -d ${logdir} ] ; then mkdir -p ${logdir}; fi
	
	# Le service est relancé uniquement si celui ci n'est plus en mémoire
	isStarted=$(ps aux | grep dummy.sh | grep -v grep | wc -l)  # ou `ps aux | grep [d]ummy.sh | wc -l`
	if [ ${isStarted} = 0 ]; then
	    echo "$(date) Lancement du programme" >> ${logdir}/${file}.log
	    ${repwork}/${file}.sh &
	else
	    echo "$(date) Le programme est déjà en cours d'exécution" >> ${logdir}/${file}.log
	fi
	;;
     stop)
     # On se sert du PID stocké dans un fichier pour arrêter le serveur
	echo "$(date) Arrêt du programme" >> ${logdir}/${file}.log
	kill -9 $(cat ${varrun}/${file}/${file}.pid)
	rm -f ${varrun}/${file}/${file}.pid
	;;
     *)
	echo "no comment";;
  esac

Teste de fonctionnement local.

vanvincq@Debian-Laptop ~ $ /etc/init.d/dummyd.sh start
read: 10: arg count
read: 10: arg count
read: 10: arg count
read: 10: arg count
read: 10: arg count
...
vanvincq@Debian-Laptop ~ $ tail /tmp/log/dummy.log
dimanche 29 janvier 2012, 16:55:24 (UTC+0100) Lancement du programme

Initialisation du script au niveau de démarrage 2, 3 et 5 de la machine.

vanvincq@Debian-Laptop ~ $ update-rc.d dummyd.sh start 50 2 3 5 . stop 50 1 4 6 .

Redémarrage.

vanvincq@Debian-Laptop ~ $ reboot

Vérification bon fonctionnement.

vanvincq@Debian-Laptop ~ $ ps aux |grep [d]ummy
root      1663 15.2  0.0   3952   604 ?        S    17:07   0:16 /bin/sh /usr/sbin/dummy.sh
root      1664  0.4  0.0   3736   424 ?        Ss   17:07   0:00 startpar -f -- dummyd.sh

Suppression du script.

vanvincq@Debian-Laptop ~ $ update-rc.d -f dummyd.sh remove

10.1.3. Troisième partie

Vérification si existance rc.local

vanvincq@Debian-Laptop ~ $ locate rc.local
/etc/rc.local
/etc/init.d/rc.local
/etc/rc2.d/S25rc.local
/etc/rc3.d/S25rc.local
/etc/rc4.d/S25rc.local
/etc/rc5.d/S25rc.local
/var/lib/update-rc.d/rc.local

Conservation de l'ancien script.

vanvincq@Debian-Laptop ~ $ mv /etc/init.d/rc.local /etc/init.d/rc.local.old

Création du nouveau script.

vanvincq@Debian-Laptop /etc/init.d/ $ vim rc.local
vanvincq@Debian-Laptop /etc/init.d/ $ chmod 700 rc.local
vanvincq@Debian-Laptop /etc/init.d/ $ cat ./rc.local
#!/bin/sh
apt-get update >> /tmp/update.log
vanvincq@Debian-Laptop ~ $ update-rc.d rc.local remove
vanvincq@Debian-Laptop ~ $ update-rc.d rc.local start 50 2 3 5

Vérification après redémarrage.

vanvincq@Debian-Laptop ~ $ sudo tail /tmp/update.log
Err http://security.debian.org squeeze/updates/non-free amd64 Packages
  Something wicked happened resolving 'security.debian.org:http' (-5 - No address associated with hostname)
Err http://mozilla.debian.net squeeze-backports/iceweasel-release amd64 Packages
  Something wicked happened resolving 'mozilla.debian.net:http' (-5 - No address associated with hostname)
Err http://apt.jenslody.de any/main Sources
  Something wicked happened resolving 'apt.jenslody.de:http' (-5 - No address associated with hostname)
Err http://mozilla.debian.net squeeze-backports/icedove-release amd64 Packages
  Something wicked happened resolving 'mozilla.debian.net:http' (-5 - No address associated with hostname)
Err http://apt.jenslody.de any/main amd64 Packages
  Something wicked happened resolving 'apt.jenslody.de:http' (-5 - No address associated with hostname)
vanvincq@Debian-Laptop ~ $ update-rc.d rc.local remove

10.1.4. Quatrième partie

Installation de rcconf.

vanvincq@Debian-Laptop ~ $ apt-get install rcconf
vanvincq@Debian-Laptop ~ $ apt-cache depends rcconf
rcconf
 Dépend: whiptail
 Dépend: whiptail-provider
    whiptail
  Dépend: dialog
  Dépend: sysv-rc
  Dépend: perl
  Dépend: perl-modules
  Est en conflit avec: file-rc

rcconf est donc écrit en perl.

10.1.5. Cinquième partie

Autre commande utile :

vanvincq@Debian-Laptop ~ $ chkconfig --list
acpi-fakekey              0:off  1:off  2:on   3:on   4:on   5:on   6:off
acpi-support              0:off  1:off  2:on   3:on   4:on   5:on   6:off
acpid                     0:off  1:off  2:on   3:on   4:on   5:on   6:off
alsa-utils                0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
anacron                   0:off  1:off  2:on   3:on   4:on   5:on   6:off
apmd                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
atd                       0:off  1:off  2:on   3:on   4:on   5:on   6:off
avahi-daemon              0:off  1:off  2:on   3:on   4:on   5:on   6:off
binfmt-support            0:off  1:off  2:on   3:on   4:on   5:on   6:off
bluetooth                 0:off  1:off  2:on   3:on   4:on   5:on   6:off
bootlogd                  0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
bootlogs                  0:off  1:on   2:on   3:on   4:on   5:on   6:off
bootmisc.sh               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
checkfs.sh                0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
checkroot.sh              0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
console-setup             0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
cpufrequtils              0:off  1:off  2:on   3:on   4:on   5:on   6:off
cron                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
cups                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
dbus                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
dummyd.sh                 0:off  1:off  2:off  3:off  4:off  5:off  6:off
exim4                     0:off  1:off  2:on   3:on   4:on   5:on   6:off
fancontrol                0:off  1:off  2:on   3:on   4:on   5:on   6:off
fuse                      0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
gdm3                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
hdparm                    0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
hostname.sh               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
hwclock.sh                0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
hwclockfirst.sh           0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
ifupdown                  0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
ifupdown-clean            0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
kbd                       0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
kerneloops                0:off  1:off  2:on   3:on   4:on   5:on   6:off
kexec                     0:off  1:off  2:off  3:off  4:off  5:off  6:off
kexec-load                0:off  1:off  2:off  3:off  4:off  5:off  6:off
keyboard-setup            0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
keymap.sh                 0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
killprocs                 0:off  1:on   2:off  3:off  4:off  5:off  6:off
live-boot                 0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
live-config               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
lm-sensors                0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
loadcpufreq               0:off  1:off  2:on   3:on   4:on   5:on   6:off
module-init-tools         0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
mountall-bootclean.sh     0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
mountall.sh               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
mountdevsubfs.sh          0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
mountkernfs.sh            0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
mountnfs-bootclean.sh     0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
mountnfs.sh               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
mountoverflowtmp          0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
mtab.sh                   0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
network-manager           0:off  1:off  2:on   3:on   4:on   5:on   6:off
networking                0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
nfs-common                0:off  1:off  2:on   3:on   4:on   5:on   6:off  S:on 
pcmciautils               0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
portmap                   0:off  1:off  2:on   3:on   4:on   5:on   6:off  S:on 
pppd-dns                  0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
procps                    0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
rc.local                  0:off  1:off  2:on   3:on   4:on   5:on   6:off
rcS                       0:off  1:off  2:off  3:off  4:off  5:off  6:off
rmnologin                 0:off  1:off  2:on   3:on   4:on   5:on   6:off
rsync                     0:off  1:off  2:on   3:on   4:on   5:on   6:off
rsyslog                   0:off  1:off  2:on   3:on   4:on   5:on   6:off
saned                     0:off  1:off  2:on   3:on   4:on   5:on   6:off
sendsigs                  0:off  1:off  2:off  3:off  4:off  5:off  6:off
ssh                       0:off  1:off  2:on   3:on   4:on   5:on   6:off
stop-bootlogd             0:off  1:off  2:on   3:on   4:on   5:on   6:off
stop-bootlogd-single      0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
sudo                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
udev                      0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
udev-mtab                 0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
umountfs                  0:off  1:off  2:off  3:off  4:off  5:off  6:off
umountnfs.sh              0:off  1:off  2:off  3:off  4:off  5:off  6:off
umountroot                0:off  1:off  2:off  3:off  4:off  5:off  6:off
unattended-upgrades       0:off  1:off  2:off  3:off  4:off  5:off  6:off
urandom                   0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
x11-common                0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on