Day 7 Understanding package manager and systemctl

Day 7 Understanding package manager   
                              and systemctl

What is Package?

A package is usually referred to an application but it could be a GUI application, command line tool or a software library (required by other software programs). A package is essentially an archive file containing the binary executable, configuration file and sometimes information about the dependencies.

What is Package Manager?

A package manager in Linux is a software tool that automates the process of installing, updating, configuring, and removing software packages on a Linux system. It simplifies the management of software by handling dependencies, version tracking, and installation tasks. Package managers are integral to the package-based distribution model of many Linux distributions.

There are several package managers in use across various Linux distributions, and each distribution typically has its own package management system. Here are a few examples:

  1. APT (Advanced Package Tool):

    • Used by Debian-based distributions, including Debian, Ubuntu, and derivatives.

    • Commands: apt-get, apt, aptitude.

  2. YUM (Yellowdog Updater Modified):

    • Used by Red Hat-based distributions, including CentOS, Fedora, and RHEL.

    • Commands: yum, dnf (in newer distributions).

  3. zypper:

    • Used by openSUSE and SUSE Linux Enterprise.

    • Command: zypper.

  4. Pacman:

    • Used by Arch Linux and Arch-based distributions.

    • Command: pacman.

  5. Portage:

    • Used by Gentoo Linux.

    • Command: emerge.

  6. Dpkg:

    • The low-level package management tool used by Debian-based distributions.

    • Commands: dpkg, apt-get utilizes dpkg as a backend.

  7. RPM (RPM Package Manager):

    • The low-level package management tool used by Red Hat-based distributions.

    • Commands: rpm, yum utilizes rpm as a backend.

What is Systemd?

systemd is a system and service manager for Linux operating systems. It is designed to be a replacement for the traditional Unix init system and other init-related tools. systemd is now the default initialization system for a significant number of Linux distributions, including popular ones such as Ubuntu, Fedora, CentOS, and others.

What is the Linux Systemctl Command?

Now, imagine you have a remote control for your Linux system – that’s what systemctl is. It’s like your boss for telling the system what to do. With this tool, you can start, stop, or restart services (think of them like programs running in the background). Want something to start automatically when your computer turns on? systemctl helps with that too. It’s also good for checking how things are going – like looking at logs or figuring out what other things a service needs to work properly. So, if you’re in charge of a Linux system, systemctl is your go-to tool for keeping things organized and running well.

Syntax of systemctl command :-

systemctl [command] [service]

[command] \= The action we want to perform (start, stop, enable, disable, etc.)

[service] = The name of the service we want to perform the action on.

Options available in systemctl command

OptionsDescriptionSyntax
–versionThis option displays the version number of the systemctl command.systemctl --version
–helpThis option displays the help manual for systemctl, including a list of available options and commandssystemctl --help
–typeThe argument in this case should be comma-separated list of unit types such as service and socket.systemctl --type=service
–allThis option lists all available units, including those that are inactive.systemctl --all
–failedThis option lists all units that have failed.systemctl --failed
–usertalk to service manager of calling user, instead of system.systemctl --user
–forceThis option forces the service to start or stop, even if it has dependencies that are not yet started or stopped.systemctl stop --force httpd.service
–no-blockThis option starts or stops the service without blocking the shell, allowing the user to continue to use the shell while the service is starting or stopping.systemctl start --no-block httpd.service
–stateThis option is used to filter the output based on the specified unit state. You can specify one or more-unit states separated by commas, such as active, inactive, failed, and activating.systemctl list-units --state=failed
-r, –recursiveThis option is used to show units of local containers as well.systemctl list-units --recursive
–show-typesThis option is used to show the types of sockets along with showing sockets.systemctl list-sockets --show-types
–job-mode=This option controls how to deal with already queued jobs in case of queuing a new job. There are three available modes:systemctl isolate graphical.target --job-mode=replace
-i, –ignore-inhibitorsThis option is used to ignore inhibitor locks when requesting a system shutdown or sleep state.systemctl poweroff --ignore-inhibitors
-q, –quietThis option is used to suppress the printing of results of various commands and the hints about the truncated lines.systemctl daemon-reload --quiet
–no-wallThis option is used to not send a wall message before power-off, halt, or reboot.systemctl halt --no-wall

Task:-

Check the status of docker service in your system

Read about the commands systemctl vs service

systemctl:

  1. Description:

    • systemctl is a more modern and feature-rich command that is part of the systemd system and service manager.
  2. Functionality:

    • It is a central tool for controlling the systemd system and its services.

    • Manages system services, targets, sockets, devices, and more.

    • Provides extensive features for service control, status monitoring, and configuration.

  3. Usage Examples:

     # View the status of a service
     systemctl status service_name
    
     # Start, stop, or restart a service
     systemctl start service_name
     systemctl stop service_name
     systemctl restart service_name
    
     # Enable or disable a service at boot
     systemctl enable service_name
     systemctl disable service_name
    
  4. Additional Features:

    • Dependency tracking for services.

    • Detailed service status information.

    • Integration with the systemd logging system.

service:

  1. Description:

    • service is a simpler and older command that is often associated with traditional SysV init systems.
  2. Functionality:

    • It is a wrapper script designed for backward compatibility with SysV init scripts.

    • Primarily used for starting, stopping, and restarting services.

  3. Usage Examples:

     # Start, stop, or restart a service
     service service_name start
     service service_name stop
     service service_name restart
    
     # Check the status of a service
     service service_name status
    
  4. Limitations:

    • Limited capabilities compared to systemctl.

    • Provides basic service management without advanced features.