#90DaysOfDevOps - Day 7: Linux Package Manager and systemctl, systemd

Introduction

Greetings on the 7th day of the 90DaysDevOps Challenge! Today's adventure leads us into the realm of Linux package management. We'll unravel the role of package managers, understand diverse package types in various Linux flavors, and delve into the prowess of systemctl and systemd commands. With hands-on tasks, we'll harness their potential for efficient system service management. Get ready to enhance your skills and navigate the intricacies of software handling in the Linux environment. Let's embark on this enlightening journey, where we decode package management and wield powerful commands to bolster our DevOps expertise.

What is package manager in Linux?

A package manager is a collection of software tools that automate the process of installing, upgrading, configuring, and removing software. A package manager maintains a database of information about installed packages (called the package database) that enables the package manager to uninstall software, establish whether a new package’s dependencies have been met, and determine whether a package you’re trying to install has already been installed.

What is a package?

Package generally contains metadata, such as the software's name, description of its purpose, version number, vendor, checksum, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.

Different kinds of package managers

Package Managers differ based on the packaging system but the same packaging system may have more than one package manager. There are many but we will look at the most commonly used ones.

rpm

This is the package management system used by Linux Standard Base (LSB)-compliant distributions for the low-level handling of packages. It can query, install, verify, upgrade, and remove packages, and is more frequently used by Fedora-based distributions, such as RHEL and CentOS.

yum

It adds the functionality of automatic updates and package management with dependency management to RPM-based systems. As a high-level tool, yum works with repositories.

dpkg

It is a low-level package manager for Debian-based systems. It can install, remove, provide information about, and build *.deb packages but it can’t automatically download and install their corresponding dependencies.

apt

It's a high-level package manager for Debian and derivatives and provides a simple way to retrieve and install packages, including dependency resolution, from multiple sources using the command line. Unlike dpkg, apt-get does not work directly with *.deb files, but with the package's proper name.

Tasks

  1. Installing docker package on Ubuntu

    First, we update the installed packages.

     ubuntu@~$: sudo apt update -y
    

    Then we upgrade the installed packages.

     ubuntu@~$: sudo apt upgrade -y
    

    We start with installing docker package

     ubuntu@~$: sudo apt install docker.io -y
    

    Once installed we can check the version of docker.

     ubuntu@~$: docker -v
    
  2. Installing Jenkins on Ubuntu

    We refer to and execute the commands mentioned in the Jenkins document official website.

    https://www.jenkins.io/doc/book/installing/linux/#debianubuntu

    Jenkins requires Java in order to run. So first we install openjdk-17-jre package.

     ubuntu@~$: sudo apt update
     ubuntu@~$: sudo apt install openjdk-17-jre
    

    Next, we install jenkins package.

     ubuntu@~$: curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
       /usr/share/keyrings/jenkins-keyring.asc > /dev/null
     ubuntu@~$: echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
       https://pkg.jenkins.io/debian binary/ | sudo tee \
       /etc/apt/sources.list.d/jenkins.list > /dev/null
     ubuntu@~$: sudo apt-get install jenkins
    

systemd and systemctl

systemd

Systemd is a software suite that provides fundamental building blocks for a Linux operating system. It includes the systemd “System and Service Manager”, an init system used to bootstrap user space and manage user processes. systemd aims to unify service configuration and behavior across Linux distributions.

systemctl

The systemctl command is a systemd utility used to manage services, get information about service unit files and service states, and therefore a useful utility to know for managing services on the server while systemd is an array of components for Linux OS.

Some of the common systemctl commands

#start service
systemctl start <service_name>

#stop service
systemctl stop <service_name>

#restart service
systemctl restart <service_name>

#check the status of the service
systemctl status <service_name>

#To add the service to startup process list. 
#The service will start when the system starts.
systemctl enable <service_name>

#To remove the service from startup process list. 
#The service will not start when the system starts.
systemctl disable <service_name>

Tasks

  1. Check the status of docker service

    We use systemctl status command to check the status of docker service. This command will provide you with information about whether the Docker service is running, stopped, or in some other state, along with additional details about its status.

     ubuntu@~$: systemctl status docker
    

  2. Stop and start Jenkins service

    First, we check the current status of the Jenkins service using systemctl status jenkins command.

    We see that it's running. So we stop the service using systemctl stop jenkins . It prompts you to enter the password. After authentication is successful the Jenkins service is stopped. You can check the status by using systemctl status jenkins

    Now, we will start the Jenkins service using systemctl start jenkins It prompts you again to enter the password. After authentication is successful the Jenkins service starts. Check the status of the service using systemctl status jenkins

  3. systemctl vs service

    The service command is a more traditional way of managing services in Linux. It is often used in systems that use the SysV init system.

    The systemctl command is part of the systemd init system, which is used by many modern Linux distributions. It was developed to address some of the limitations and issues with SysV

    Running systemctl status docker

    Running service docker status

Conclusion

Today we covered the essentials of Linux package management. This included an introduction to package managers that streamline software handling, understanding software packages, and the varying types of package managers like rpm, yum, dpkg, and apt. We learned the installation procedures for Docker and Jenkins on Ubuntu, along with insights into systemd, systemctl, and service commands for managing system services. This comprehensive overview equipped us with skills in package installation, service control, and system administration in Linux environments.

"🌱 Keep learning, and spread the knowledge to inspire others. 🚀💡"

Go back to the main page