Day7: Devops Journey.

Understanding package manager and systemctl.

Package Manager and systemctl. Certainly! In Linux, package managers… | by  Vikash Anand Singh | Medium

What is a package manager in Linux?

  • A package manager is a command-line or graphical tool used to automate the process of installing, updating, and removing software packages on a Linux system.

  • Software packages are collections of files, including executables, libraries, configuration files, and documentation, that are bundled together for easy distribution and installation.

  • Package managers keep track of these packages, making it easier to manage software on a Linux system.

Functionalities of Package Manager in Linux:

Installation: Package managers facilitate the installation of software packages from repositories or local files. They automatically handle dependencies, ensuring that all required components are installed.

Dependency Resolution: Linux software often relies on other packages. Package managers detect these dependencies and fetch and install them automatically.

Upgrading: Package managers allow users to update installed software to the latest versions. This helps in keeping the system secure and up-to-date.

Removal: Uninstalling software is straightforward with package managers. They ensure that all related files and dependencies are removed, preventing conflicts.

Querying: Users can query the package manager to get information about installed packages, available updates, and package details.

Most Widely used Package Manager in Linux:

APT (Advanced Package Tool):

APT is a powerful and widely used package manager in the Linux world. It’s the default package manager for Debian-based distributions, including Debian itself, Ubuntu, and Linux Mint. APT simplifies software management, ensuring that users can easily install, update, and remove packages while taking care of dependencies.

Basic commands in APT:

Installing a package:

sudo apt-get install package-name

Updating the package list:

sudo apt-get update

Upgrading packages:

sudo apt-get upgrade

Removing a package:

sudo apt-get remove package-name

Searching for packages:

apt-cache search package-name

YUM :

  • Yellowdog Updater, Modified

  • It is a package manager primarily used in Red Hat-based Linux distributions such as CentOS, Fedora, and RHEL (Red Hat Enterprise Linux).

  • YUM has played a significant role in simplifying package management on these systems, although it’s important to note that in recent years, dnf (Dandified YUM) has become the modern and recommended replacement for YUM.

Installing a package:

#sudo yum install package-name

Updating & upgrading the package list:

#sudo yum update

Removing a package:

sudo yum remove package-name

dnf Package Manager

dnf is the successor to YUM and is now the recommended package manager for Fedora-based distributions. It provides a more modern and user-friendly experience. The syntax and commands for dnf are similar to yum.

Some dnf examples are:

Installing a package:

#sudo dnf install package-name

Updating packages:

#sudo dnf upgrade

Working of a Package manager:

Installing:

  • A local database is maintained by the package manager which stores all the information about installed packages, their versions and dependencies. This helps the package manager track the software installed on the system.

  • When a package is requested to be installed, then firstly the package manager for dependencies that the package relies on.

  • The next step, it downloads the package from the configured repositories to make sure it delivers the requested version.

  • The package manager installs the software by extracting the package contents to the appropriate directories on the system. It may also execute pre- and post-installation scripts to configure the software or perform other necessary tasks.

Removing:

  • When a user requests to remove a package, the package manager checks for dependencies that are no longer required by other installed packages.

  • A pre-removal script is present in most of the package manager. These scripts perform tasks such as stopping services, backing up configuration files, or notifying the user about potential issues.

  • The package manager removes the files associated with the package i.e. binaries, libraries, configuration files etc. from the system.

  • It then goes through a dependency check which where it checks for dependencies that are no longer needed. If found then they are also removed.

  • Finally it performs a verification to ensure that the package and its dependencies are successfully deleted.

systemctl and systemd

systemd:

Systemd is a system and service manager for Linux operating systems. It is designed to replace traditional init systems like SysV init and Upstart and is responsible for initializing the system, starting services, managing daemons, and monitoring system state. Its approach to managing processes is both efficient and powerful.

Some key features of systemd include:

  • Parallel startup of services, which accelerates the boot process.

  • Dependency management, ensuring that services are started in the right order.

  • Cgroups integration for resource management.

  • Enhanced logging through the journal system.

  • Socket activation, which allows services to be started on-demand.

Introduction to systemctl:

systemctl is the primary command-line interface for interacting with systemd. It provides a wide range of functions for managing services, viewing their status, and controlling the system’s behaviour.

Basic systemctl Commands:

Starting and Stopping Services:

#sudo systemctl start mysql.service

#sudo systemctl stop mysql.service

#sudo systemctl status mysql.service

Enabling and Disabling Services:

#sudo systemctl disable mysql.service

#sudo systemctl enable mysql.service

Restarting and Reloading Services:

#sudo systemctl restart mysql.service

#sudo systemctl reload mysql.service

Viewing Active Units:

#systemctl list-units --type=service

View Journal Logs:

#journalctl

Scenario based Practice:

Task1: Install Docker and Jenkins.

#sudo apt update

#sudo apt install -y docker.io

#docker --version

To access docker, we need to give permission of Docker Daemon using chmod command.

#sudo chmod 777 docker.sock

Install Jenkins:

First install Java JDK and then Copy These commands and run on your terminal to get it installed.

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \ https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian-stable binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null

ref- https://www.jenkins.io/doc/book/installing/linux/

sudo apt-get update

sudo apt-get install jenkins

#jenkins --version

Task 2: Check Docker Service Status

#sudo systemctl status docker

Task 3: Stop Jenkins Service and Capture Screenshots:

Before:

#sudo systemctl stop jenkins

#sudo systemctl status jenkins

Task 4: systemctl vs. service

  • systemctl and service are both commands used in Linux for managing services, but they come from different service management systems.

Systemctl:

  • This command is part of systemd, which is a newer init system adopted by many modern Linux distributions like CentOS 7, RHEL 7, and Ubuntu 16.04.

  • It is a command-line tool to examine and control the state of the system and service manager.

  • It can start, stop, restart, enable, or disable services.

  • Provides detailed information about services using systemctl status.

Service:

  • This originated from System V, which is one of the oldest init systems in the Linux world.

  • It is a simple command for interacting with the init system.

  • It is backward-compatible with the older init.d scripts.

  • It is less feature-rich compared to systemctl and may not support all systemd features.

Thank you for reading my blog:)