En RHEL 7 y CentOS 7 (ver guía de instalación)la forma de controlar los servicios del sistema cambia completamente. Pasamos del uso del comando «service» y de la control de servicios a través de «/etc/init.d» a la gestión a través del service manager systemctl.
La explicación la tenemos directamente en el fichero README de /etc/init.d:
# more /etc/init.d/README You are looking for the traditional init scripts in /etc/rc.d/init.d, and they are gone? Here's an explanation on what's going on: You are running a systemd-based OS where traditional init scripts have been replaced by native systemd services files. Service files provide very similar functionality to init scripts. To make use of service files simply invoke "systemctl", which will output a list of all currently running services (and other units). Use "systemctl list-unit-files" to get a listing of all known unit files, including stopped, disabled and masked ones. Use "systemctl start foobar.service" and "systemctl stop foobar.service" to start or stop a service, respectively. For further details, please refer to systemctl(1). Note that traditional init scripts continue to function on a systemd system. An init script /etc/rc.d/init.d/foobar is implicitly mapped into a service unit foobar.service during system initialization. Thank you! Further reading: man:systemctl(1) man:systemd(1) http://0pointer.de/blog/projects/systemd-for-admins-3.html http://www.freedesktop.org/wiki/Software/systemd/Incompatibilities
Vamos a ver entonces los comandos básicos de gestión de servicios con systemctl.
Listar servicios del sistema
El comando systemctl sin parámetros nos mostrará el listado de todos los servicios del sistema, incluyendo los que están activos, parados o en estado fallido.
# systemctl UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Formats File System Automo sys-devices-pci0...et1:0:0-1:0:0:0-block-sr0.device loaded active plugged VBOX_CD-ROM sys-devices-pci0...0-0000:00:03.0-net-enp0s3.device loaded active plugged PRO/1000 MT Desktop Adapter sys-devices-pci0...-0000:00:05.0-sound-card0.device loaded active plugged 82801AA AC'97 Audio Controller sys-devices-pci0...:0-2:0:0:0-block-sda-sda1.device loaded active plugged VBOX_HARDDISK sys-devices-pci0...:0-2:0:0:0-block-sda-sda2.device loaded active plugged LVM PV F3zoLx-uSaP-faJK-Vhz7-iJC4-XFml-QjX37E on /de sys-devices-pci0...et2:0:0-2:0:0:0-block-sda.device loaded active plugged VBOX_HARDDISK
Los servicios son llamados UNITS, y como veis podemos visualizar el estado del proceso, si está cargado en el sistema, descripción…
El parámetro list-units muestra la misma información:
# systemctl list-units
Ver estado de un servicio
Tan sencillo como pasar el parámetro status + el servicio. Vamos a ver el estado del firewall:
# systemctl status firewalld.service firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled) Active: active (running) since sáb 2014-08-23 17:51:42 CEST; 9min ago Main PID: 549 (firewalld) CGroup: /system.slice/firewalld.service └─549 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid ago 23 17:51:42 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Como podéis observar nos ofrece mucha más información que el típico status que teníamos en «init.d» y «service». Incluso podemos ver el log completo o sólo la parte que engloba el arranque:
# systemctl status network.service network.service - LSB: Bring up/down networking Loaded: loaded (/etc/rc.d/init.d/network) Active: active (exited) since sáb 2014-08-23 17:51:45 CEST; 10min ago Process: 830 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS) ago 23 17:51:43 localhost.localdomain systemd[1]: Starting LSB: Bring up/down networking... ago 23 17:51:44 localhost.localdomain network[830]: Bringing up loopback interface: Could not load file '/etc/sysconfig...g-lo' ago 23 17:51:44 localhost.localdomain network[830]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' ago 23 17:51:44 localhost.localdomain network[830]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' ago 23 17:51:44 localhost.localdomain network[830]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' ago 23 17:51:44 localhost.localdomain network[830]: [ OK ] ago 23 17:51:45 localhost.localdomain network[830]: Bringing up interface enp0s3: [ OK ] ago 23 17:51:45 localhost.localdomain systemd[1]: Started LSB: Bring up/down networking. Hint: Some lines were ellipsized, use -l to show in full.
Arrancar, parar y reiniciar servicios
Ya sabemos los servicios que hay en el sistema, así que podemos invocarlos para iniciarlos, pararlos o reiniciarlos:
Iniciar servicio:
# systemctl start firewalld.service
Parar servicio:
# systemctl stop firewalld.service
Reiniciar servicio:
# systemctl restart firewalld.service
Recargar servicio (si lo permite):
# systemctl reload firewalld.service
chkconfig vs systemctl
Esto lo quiero explicar más detenidamente en otro artículo, pero sólo añadir que chkconfig también es sustituido por systemctl.
Por ejemplo, para quitar la red del arranque:
[root@localhost ~]# systemctl disable NetworkManager.service rm '/etc/systemd/system/multi-user.target.wants/NetworkManager.service' rm '/etc/systemd/system/dbus-org.freedesktop.NetworkManager.service' rm '/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service'
Y vemos que al lanzar un status aparece el servicio activo pero «disabled» en el arranque:
[root@localhost ~]# systemctl status NetworkManager.service NetworkManager.service - Network Manager Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; disabled) Active: active (running) since sáb 2014-08-23 17:51:43 CEST; 15min ago Main PID: 676 (NetworkManager)
Si lo volvemos a configurar:
[root@localhost ~]# systemctl enable NetworkManager.service ln -s '/usr/lib/systemd/system/NetworkManager.service' '/etc/systemd/system/dbus-org.freedesktop.NetworkManager.service' ln -s '/usr/lib/systemd/system/NetworkManager.service' '/etc/systemd/system/multi-user.target.wants/NetworkManager.service' ln -s '/usr/lib/systemd/system/NetworkManager-dispatcher.service' '/etc/systemd/system /dbus-org.freedesktop.nm-dispatcher.service'
[root@localhost ~]# systemctl status NetworkManager.service NetworkManager.service - Network Manager Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled) Active: active (running) since sáb 2014-08-23 17:51:43 CEST; 16min ago
Esto es lo que tenéis que saber para iniciaros con systemctl. Recordad que la página man del comando tiene toda la información necesaria para administración avanzada. En algún otro artículo iré poniendo más funcionalidades interesantes (que no son pocas).