Understanding Package Manager and Systemctl ๐Ÿš€

Ramiz TakildarRamiz Takildar
4 min read

In the world of Linux, package managers and systemd's systemctl command play crucial roles in managing software and services. This blog will break down these components to help you understand their importance and functionality.

What is a Package Manager? ๐Ÿ“ฆ

A package manager is a tool that automates the installation, upgrade, configuration, and removal of software packages. Hereโ€™s why they are essential:

  • Simplifies Software Management: ๐ŸŒ

    • Instead of manually downloading and installing software, package managers handle it for you.
  • Dependency Resolution: ๐Ÿ”—

    • They automatically manage dependencies, ensuring that all required packages are installed.
  • Version Control: โณ

    • Package managers keep track of installed versions and can upgrade or downgrade as needed.
  • APT (Advanced Package Tool): Used in Debian-based distributions (like Ubuntu).

  • YUM (Yellowdog Updater, Modified): Common in Red Hat-based systems (like CentOS).

  • DNF (Dandified YUM): The next generation of YUM, used in newer Fedora and Red Hat systems.

  • Pacman: The package manager for Arch Linux.

What is systemctl? โš™๏ธ

systemctl is a command-line utility that is part of the systemd system and service manager. It controls the system and service manager, making it easier to manage system services. Hereโ€™s what you need to know:

  • Start and Stop Services: ๐Ÿšฆ

    • Use systemctl start [service] to start a service and systemctl stop [service] to stop it.
  • Enable and Disable Services: ๐Ÿ”’

    • To ensure a service starts on boot, use systemctl enable [service]. To prevent it from starting, use systemctl disable [service].
  • Check Status of Services: ๐Ÿ“Š

    • Use systemctl status [service] to get the current status of a service.

Key systemctl Commands

  • List All Services:

      systemctl list-units --type=service
    
  • Restart a Service:

      systemctl restart [service]
    
  • View Logs:

      journalctl -u [service]
    

Tasks

๐Ÿ› ๏ธ Installing Docker and Jenkins

Ubuntu Installation

  1. Update Package Index:

     sudo apt update
    
  2. Install Docker:

     sudo apt install docker.io -y
    
  3. Install Jenkins: First, add the Jenkins repository:

     wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
     echo deb http://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list
     sudo apt update
     sudo apt install jenkins -y
    

CentOS Installation

  1. Update Package Index:

     sudo yum update -y
    
  2. Install Docker:

     sudo yum install docker -y
    
  3. Install Jenkins: First, add the Jenkins repository:

     sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
     sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
     sudo yum install jenkins -y
    

๐Ÿณ Checking Docker Service Status

Once youโ€™ve installed Docker, letโ€™s check its status:

sudo systemctl status docker

This command will display the current state of the Docker service. โœ…

๐Ÿšฆ Managing Jenkins Service

To manage the Jenkins service, you can stop it and check its status:

  1. Stop Jenkins:

     sudo systemctl stop jenkins
    
  2. Check Status Before and After:

     sudo systemctl status jenkins
    
    • Before Stopping: ![Before Screenshot]

    • After Stopping: ![After Screenshot]

โš–๏ธ Understanding Systemctl vs. Service

  • systemctl: A newer command to manage system services using systemd.

    • Example: systemctl status docker
  • service: An older command that works with System V-style init scripts.

    • Example: service docker status

For a detailed comparison, check out this article.

๐Ÿ”ง Automate Service Management

To streamline our workflow, letโ€™s create a script to start and stop the Docker and Jenkins services:

#!/bin/bash

case $1 in
  start)
    sudo systemctl start docker
    sudo systemctl start jenkins
    ;;
  stop)
    sudo systemctl stop docker
    sudo systemctl stop jenkins
    ;;
  *)
    echo "Usage: $0 {start|stop}"
    exit 1
esac

๐Ÿ Enable and Disable Services

Use the following commands to manage service autostart:

  • Enable Docker on Boot:

      sudo systemctl enable docker
    
  • Disable Jenkins from Starting on Boot:

      sudo systemctl disable jenkins
    

๐Ÿ“œ Analyzing Logs

To view logs for Docker and Jenkins, use journalctl:

sudo journalctl -u docker
sudo journalctl -u jenkins

Findings:

  • Check for any errors or warnings that might indicate issues during operation. ๐Ÿ”
0
Subscribe to my newsletter

Read articles from Ramiz Takildar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ramiz Takildar
Ramiz Takildar