Table des matières
Par Dominique Colombani le samedi 17 février 2007, 10:04 - Linux - Lien permanent
Vous voulez connaître le niveau par défaut de votre environnement Ubuntu fraîchement installé, et vous ouvrez le fichier /etc/inittab pour voir la valeur du initdefault.
Ah, le fichier /etc/inittab n'existe pas ?
Panique, recherche, interrogation et ... découverte : Ubuntu utilise maintenant un nouveau mécanisme qui remplace le traditionnel init : upstart !
Ce nouveau mécanisme utilise la notion de job et d'événement. Les actions à réaliser sont définies au sein d'un job, par un script shell. Le job contient une liste d'actions sur ce qu'il doit faire lorsqu'un événement donné se produit.
Les jobs sont placés dans le répertoire /etc/init, dont voici une liste typique :
/etc/init: total used in directory 272 available 631696 drwxr-xr-x 2 root root 4096 Jul 6 07:33 . drwxr-xr-x 168 root root 12288 Jul 6 09:52 .. -rw-r--r-- 1 root root 320 Jan 7 14:13 acpid.conf -rw-r--r-- 1 root root 268 Apr 14 13:36 alsa-restore.conf -rw-r--r-- 1 root root 267 Apr 14 13:36 alsa-store.conf -rw-r--r-- 1 root root 278 Jun 20 2010 anacron.conf -rw-r--r-- 1 root root 1299 Apr 21 02:43 apport.conf -rw-r--r-- 1 root root 261 Jun 27 2010 atd.conf -rw-r--r-- 1 root root 541 Apr 7 01:14 avahi-daemon.conf -rw-r--r-- 1 root root 509 Dec 21 2010 console-setup.conf -rw-r--r-- 1 root root 356 Apr 21 00:56 control-alt-delete.conf -rw-r--r-- 1 root root 297 Jan 5 11:23 cron.conf -rw-r--r-- 1 root root 1721 Apr 19 22:08 cups.conf -rw-r--r-- 1 root root 459 Feb 24 16:51 dbus.conf -rw-r--r-- 1 root root 273 Jan 12 22:28 dmesg.conf -rw-r--r-- 1 root root 291 Nov 2 2010 failsafe-x.conf -rw-r--r-- 1 root root 1162 Apr 14 12:19 gdm.conf -rw-r--r-- 1 root root 317 Nov 17 2010 hostname.conf -rw-r--r-- 1 root root 444 Mar 21 09:25 hwclock-save.conf -rw-r--r-- 1 root root 557 Mar 21 09:25 hwclock.conf -rw-r--r-- 1 root root 571 Jan 27 19:37 irqbalance.conf -rw-r--r-- 1 root root 367 Apr 1 16:05 module-init-tools.conf -rw-r--r-- 1 root root 349 Apr 14 19:39 mountall-net.conf -rw-r--r-- 1 root root 261 Apr 14 19:39 mountall-reboot.conf -rw-r--r-- 1 root root 1201 Apr 14 19:39 mountall-shell.conf -rw-r--r-- 1 root root 943 Apr 14 19:39 mountall.conf -rw-r--r-- 1 root root 397 Apr 14 19:39 mounted-debugfs.conf -rw-r--r-- 1 root root 427 Apr 14 19:39 mounted-dev.conf -rw-r--r-- 1 root root 480 Apr 14 19:39 mounted-proc.conf -rw-r--r-- 1 root root 1663 Apr 14 19:39 mounted-tmp.conf -rw-r--r-- 1 root root 629 Apr 14 19:39 mounted-varrun.conf -rw-r--r-- 1 root root 948 Feb 3 18:15 mysql.conf -rw-r--r-- 1 root root 1611 Dec 13 2010 network-interface-security.conf -rw-r--r-- 1 root root 740 Dec 13 2010 network-interface.conf -rw-r--r-- 1 root root 330 Apr 15 06:50 network-manager.conf -rw-r--r-- 1 root root 332 Jun 3 2010 networking.conf -rw-r--r-- 1 root root 475 Mar 10 15:57 nmbd.conf -rw-r--r-- 1 root root 326 Mar 26 2010 plymouth-log.conf -rw-r--r-- 1 root root 899 Mar 18 23:34 plymouth-splash.conf -rw-r--r-- 1 root root 792 Dec 13 2010 plymouth-stop.conf -rw-r--r-- 1 root root 367 Jan 25 23:29 plymouth-upstart-bridge.conf -rw-r--r-- 1 root root 1073 Dec 13 2010 plymouth.conf -rw-r--r-- 1 root root 296 Dec 21 2010 procps.conf -rw-r--r-- 1 root root 1529 Apr 21 00:56 rc-sysinit.conf -rw-r--r-- 1 root root 387 Apr 21 00:56 rc.conf -rw-r--r-- 1 root root 822 Apr 21 00:54 rcS.conf -rw-r--r-- 1 root root 343 Jan 12 22:28 rsyslog.conf -rw-r--r-- 1 root root 230 Mar 18 12:27 setvtrgb.conf -rw-r--r-- 1 root root 387 Apr 28 11:44 smbd.conf -rw-r--r-- 1 root root 574 Apr 2 12:06 ssh.conf -rw-r--r-- 1 root root 228 Apr 21 00:54 tty1.conf -rw-r--r-- 1 root root 213 Apr 21 00:54 tty2.conf -rw-r--r-- 1 root root 213 Apr 21 00:54 tty3.conf -rw-r--r-- 1 root root 213 Apr 21 00:54 tty4.conf -rw-r--r-- 1 root root 213 Apr 21 00:54 tty5.conf -rw-r--r-- 1 root root 213 Apr 21 00:54 tty6.conf -rw-r--r-- 1 root root 624 Apr 7 14:42 udev-fallback-graphics.conf -rw-r--r-- 1 root root 769 Apr 7 14:42 udev-finish.conf -rw-r--r-- 1 root root 316 Apr 7 14:42 udev.conf -rw-r--r-- 1 root root 356 Apr 7 14:42 udevmonitor.conf -rw-r--r-- 1 root root 331 Apr 7 14:42 udevtrigger.conf -rw-r--r-- 1 root root 473 Mar 22 21:45 ufw.conf -rw-r--r-- 1 root root 329 Apr 21 00:56 upstart-socket-bridge.conf -rw-r--r-- 1 root root 331 Apr 21 00:56 upstart-udev-bridge.conf -rw-r--r-- 1 root root 683 Mar 17 01:39 ureadahead-other.conf -rw-r--r-- 1 root root 889 Mar 17 01:39 ureadahead.conf
La commande initctl list fournit la liste des jobs lancés, actifs ou en attente :
root@guidella:/etc# initctl list avahi-daemon start/running, process 1131 mountall-net stop/waiting nmbd start/running, process 1766 rc stop/waiting rsyslog start/running, process 1057 tty4 start/running, process 1148 udev start/running, process 465 upstart-udev-bridge start/running, process 447 ureadahead-other stop/waiting apport stop/waiting console-setup stop/waiting hwclock-save stop/waiting irqbalance start/running, process 1252 plymouth-log stop/waiting smbd start/running, process 1054 tty5 start/running, process 1152 atd start/running, process 1241 dbus start/running, process 1088 failsafe-x stop/waiting plymouth stop/waiting ssh start/running, process 1052 udev-fallback-graphics stop/waiting control-alt-delete stop/waiting hwclock stop/waiting mounted-proc stop/waiting network-manager start/running, process 1140 alsa-store stop/waiting module-init-tools stop/waiting setvtrgb stop/waiting alsa-restore stop/waiting cron start/running, process 1240 gdm start/running, process 1110 mountall stop/waiting mounted-debugfs stop/waiting acpid start/running, process 1232 plymouth-stop stop/waiting rcS stop/waiting ufw start/running mounted-varrun stop/waiting rc-sysinit stop/waiting cups start/running, process 1126 upstart-socket-bridge start/running, process 871 anacron stop/waiting tty2 start/running, process 1226 udevtrigger stop/waiting mounted-dev stop/waiting tty3 start/running, process 1227 udev-finish stop/waiting hostname stop/waiting mountall-reboot stop/waiting mysql start/running, process 1284 mountall-shell stop/waiting mounted-tmp stop/waiting network-interface (vboxnet0) start/running network-interface (lo) start/running network-interface (eth0) start/running network-interface (eth1) start/running plymouth-splash stop/waiting plymouth-upstart-bridge stop/waiting tty1 start/running, process 2065 udevmonitor stop/waiting dmesg stop/waiting network-interface-security (network-manager) start/running network-interface-security (network-interface/eth1) start/running network-interface-security (network-interface/eth0) start/running network-interface-security (network-interface/vboxnet0) start/running network-interface-security (network-interface/lo) start/running network-interface-security (networking) start/running networking stop/waiting procps stop/waiting tty6 start/running, process 1230 ureadahead stop/waiting root@guidella:/etc#
Et le contenu typique d'un fichier job est :
# tty1 - getty # # This service maintains a getty on tty1 from the point the system is # started until it is shut down again. start on stopped rc RUNLEVEL=[2345] stop on runlevel [!2345] respawn exec /sbin/getty -8 38400 tty1
On y trouve tout simplement les actions à mener lorsqu'un événement (runlevel-2, runlevel-3, ... ou shutdown) se produit, et les instructions à exécuter lorsque le job est lancé.
# rc - System V runlevel compatibility # # This task runs the old System V-style rc script when changing between # runlevels. description "System V runlevel compatibility" author "Scott James Remnant <scott@netsplit.com>" start on runlevel [0123456] stop on runlevel [!$RUNLEVEL] export RUNLEVEL export PREVLEVEL console output env INIT_VERBOSE task exec /etc/init.d/rc $RUNLEVEL
On retrouve un fonctionnement habituel, qui lance les scripts dans rc2.d lorsqu'on entre dans le niveau 2, et arrête le job lorsqu'on entre dans d'autres niveaux. On remarque que le script exécuté par le job est un peu plus complexe, et on voit l'un des intérêts de ce nouveau mécanisme, à savoir éviter d'écrire un script uniquement pour le placer dans une ligne de /etc/inittab.
A l'issue de ce petit tour, vous vous demandez peut être quel est l'intérêt de ce changement ?
Pour ma part, j'en vois un majeur, qu'on ne peut pas réaliser avec le init classique sans aller modifier le fichier inittab. Il est possible d'arrêter ou de lancer temporairement et interactivement un job, c'est à dire d'être dans un niveau de fonctionnement donné sans que ce job ne continue à tourner, à l'aide des commandes start et stop.
Par exemple stop tty1 arrête le processus de login lancé sur le port virtuel tty1. Essayez donc de faire la même chose de façon interactive avec un init classique : voues êtes obligés de modifier /etc/inittab, et de faire un telinit q. Et si vous oubliez ensuite d'annuler votre modification dans /etc/inittab, votre système reste configuré de travers, ce qui ne sera pas le cas avec upstart puisque vous n'avez rien modifié aux fichiers de configuration.
Oh j'allais oublier de donner la réponse à la question. Sous Ubuntu, le niveau par défaut est le 2, et on peut le voir en lisant le contenu du fichier /etc/init/rc-sysinit.conf.