Désactiver des services au démarrage de Linux

Désactiver des services lancés automatiquement au démarrage par Linux pour optimiser la batterie
  • Linux

Debian started services 

Je cherche à optimiser la durée de la batterie sur mon laptop avec Debian 9 installé dessus. Désactiver des programmes au démarrage est une très bonne idée, car on ne se sert pas de la plupart au quotidien, notamment lorsque l’on utilise son pc en pc pro et perso.

En faisant cela, je suis passé de 1.1GO de consommation de RAM à 0.7GO… un tiers de resources en plus au démarrage.

J’ai toujours utilisé sysv-rc-conf pour désactiver les services au démarrage. Seulement ça ne fonctionne plus sous Debian 9, alors que sous Jessie (Debian 8), je n’avais aucun problème, enfin.

J’ai également tenté d’utilisrt bum et rcconf, toujours le même problème : certains services démarrent quand même.

Lister les différents services lancés au démarrage

Prenons l’exemple du service « rc.local ». Pour savoir si il est lancé, la console m’affichera un +, un si non lancé.

root@debian:/home/dinath# service --status-all
 [ - ]  alsa-utils
 [ - ]  anacron
 [ + ]  apache-htcacheclean
 [ - ]  apache2
 [ + ]  avahi-daemon
 [ - ]  bluetooth
 [ - ]  bootlogs
 [ - ]  bootmisc.sh
 [ + ]  bumblebeed
 [ - ]  checkfs.sh
 [ - ]  checkroot-bootclean.sh
 [ - ]  checkroot.sh
 [ - ]  console-setup.sh
 [ - ]  cron
 [ + ]  dbus
 [ + ]  gdm3
 [ - ]  hostname.sh
 [ - ]  hwclock.sh
 [ - ]  keyboard-setup.sh
 [ - ]  killprocs
 [ - ]  kmod
 [ - ]  motd
 [ - ]  mountall-bootclean.sh
 [ - ]  mountall.sh
 [ - ]  mountdevsubfs.sh
 [ - ]  mountkernfs.sh
 [ - ]  mountnfs-bootclean.sh
 [ - ]  mountnfs.sh
 [ - ]  mysql
 [ + ]  network-manager
 [ + ]  networking
 [ + ]  openvpn
 [ - ]  pppd-dns
 [ + ]  preload
 [ + ]  procps
 [ + ]  rc.local
 [ - ]  rmnologin
 [ + ]  rsyslog
 [ - ]  sendsigs
 [ + ]  smartmontools
 [ + ]  tlp
 [ + ]  udev
 [ - ]  umountfs
 [ - ]  umountnfs.sh
 [ - ]  umountroot
 [ + ]  urandom
 [ - ]  x11-common

Ce service est automatiquement démarré par le système. Il est actuellement actif.

root@debian:/home/dinath# service rc.local status
? rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           ??debian.conf
   Active: active (exited) since sam. 2016-08-13 14:45:06 CEST; 28min ago
   CGroup: /system.slice/rc-local.service

août 13 14:45:06 debian systemd[1]: Starting /etc/rc.local Compatibility...
août 13 14:45:06 debian systemd[1]: Started /etc/rc.local Compatibility.

Une seconde commande permet de récupérer les services actifs en cours sur le système.

root@debian:/home/dinath# systemctl list-units
  UNIT                                                                                      LOAD   ACTIVE SUB       DESCRIPTION

  -.mount                                                                                   loaded active mounted   /
  backup.mount                                                                              loaded active mounted   /backup
  dev-hugepages.mount                                                                       loaded active mounted   Huge Pages File System
  dev-mqueue.mount                                                                          loaded active mounted   POSIX Message Queue File System
  home.mount                                                                                loaded active mounted   /home
  run-user-1000.mount                                                                       loaded active mounted   /run/user/1000
  share.mount                                                                               loaded active mounted   /share
  sys-fs-fuse-connections.mount                                                             loaded active mounted   FUSE Control File System
  sys-kernel-debug.mount                                                                    loaded active mounted   Debug File System
  systemd-ask-password-console.path                                                         loaded active waiting   Dispatch Password Requests to Console Directory Watch
  systemd-ask-password-wall.path                                                            loaded active waiting   Forward Password Requests to Wall Directory Watch
  init.scope                                                                                loaded active running   System and Service Manager
  session-1.scope                                                                           loaded active running   Session 1 of user dinath
  accounts-daemon.service                                                                   loaded active running   Accounts Service
  avahi-daemon.service                                                                      loaded active running   Avahi mDNS/DNS-SD Stack
  bumblebeed.service                                                                        loaded active running   Bumblebee C Daemon
  colord.service                                                                            loaded active running   Manage, Install and Generate Color Profiles
  console-setup.service                                                                     loaded active exited    Set console font and keymap
  dbus.service                                                                              loaded active running   D-Bus System Message Bus
  gdm.service                                                                               loaded active running   GNOME Display Manager
  keyboard-setup.service                                                                    loaded active exited    Set the console keyboard layout
  kmod-static-nodes.service                                                                 loaded active exited    Create list of required static device nodes for the current kernel
  ModemManager.service                                                                      loaded active running   Modem Manager
  networking.service                                                                        loaded active exited    Raise network interfaces
  NetworkManager.service                                                                    loaded active running   Network Manager
  openvpn.service                                                                           loaded active exited    OpenVPN service
  packagekit.service                                                                        loaded active running   PackageKit Daemon

Désactiver un service au démarrage

 Les autres logiciels étant inefficace, j’ai du utilisé systemctl pour les désactiver.

root@debian:/home/dinath# systemctl disable rc.local
Synchronizing state of rc.local.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable rc.local
insserv: warning: current start runlevel(s) (empty) of script `rc.local' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (2 3 4 5) of script `rc.local' overrides LSB defaults (empty).
insserv: warning: current start runlevel(s) (empty) of script `rc.local' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (2 3 4 5) of script `rc.local' overrides LSB defaults (empty).

Réactiver un service au démarrage

root@debian:/home/dinath# systemctl enable rc.local
Synchronizing state of rc.local.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable rc.local
insserv: warning: current start runlevel(s) (empty) of script `rc.local' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (2 3 4 5) of script `rc.local' overrides LSB defaults (empty).
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
   instance name specified.

Utiliser un service désactivé au démarrage

Sur ma station, j’ai désactivé au démarrage tous les services non-essentiels.

Lorsque j’en ai besoin, je les démarre en utilisant la commande :

service rc.local start

Qui me permet de démarrer le service sans qu’il soit pour autant réactivé au démarrage

 

Voici les sources (en anglais) où j’ai demandé de l’aide pour ce problème. 

Article publié le

Dernière modification le

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.