Day-9 Task: Fundamentals of Package Manager and Systemctl

shailaja sutarshailaja sutar
3 min read

What is a Package Manager in Linux?

A package manager is a tool that helps you easily install, remove, upgrade, and manage software on your Linux system. It's like a helper that makes it simple to get and manage the software you need.

What is a Package?

A package is a file that contains a software application or library, including the program itself, its settings, and info about what else it needs to work.

In teams of :

Package: A software program or library (like a game or a tool)

Package Manager: A tool that helps you easily install, update, and manage multiple software programs or libraries (like npm for JavaScript or pip for Python)

Here are the different kinds of package managers:

  1. Language-specific: npm (JavaScript), pip (Python), gem (Ruby), maven (Java), composer (PHP)

  2. Operating System: apt (Ubuntu), yum (RPM-based Linux), homebrew (macOS), chocolatey (Windows)

  3. Distribution-specific: dpkg (Debian), rpm (RPM-based Linux), portage (Gentoo Linux)

  4. Container: docker, helm (Kubernetes)

  5. Other: conda (data science), cargo (Rust), go get (Go)

Task :

  • Install Docker :

      sudo apt update
      sudo apt install docker.io
    

systemctl :

This is the tool you use to talk to systemd. With systemctl, you can start, stop, restart, and check the status of services. Think of it as a remote control for managing services on your system.

Check Docker Service Status:

  • systemctl status docker

Start Docker Service Status:

  • sudo systemctl start docker

Stop Docker Service Status:

  • sudo systemctl stop docker

Systemctl vs. Service:

Systemctl Command:

The systemctl command is a newer way of managing services in Linux, introduced with systemd (a system and service manager). It's more powerful and flexible than the service command. systemctl is used to manage system services, as well as other system resources like sockets, timers, and mounts.

Example: systemctl status docker

Service Command:

The service command is an older way of managing services in Linux. It's been around since the early days of Linux and is still supported in many systems. The service command is used to start, stop, restart, and check the status of system services.

Example: service docker status

Task :

Here I have Implemented a script to performed operations on docker services. The operations are written using function.

#!/bin/bash

# Function to start service
start_service() {
    echo "Starting The Docker ..."
        sudo systemctl start docker
    echo "Service started."
}

# Function to stop service
stop_service() {
    echo "Stopping Docker service..."
        sudo systemctl stop docker
    echo "Service stopped."
}

# Function to check the status of service
status_service() {
    echo "The status of Docker service..."
        sudo systemctl status docker
}

# Function to restart service
restart_service() {
    echo "Restarting Docker service..."
        sudo systemctl restart docker
    echo "Service restarted."
}

# Check command line arguments
if [ "$1" == "start" ]; then
    start_service
elif [ "$1" == "stop" ]; then
    stop_service
elif [ "$1" == "status" ]; then
    status_service
elif [ "$1" == "restart" ]; then
    restart_service
else
    echo "Usage: $0 {start|stop|status|restart}"
    exit 1
fi

exit 0
  • Here you can also use journalctl to analyse the logs of the Docker service.

    Stay tune for more.... and let's learn together towards the success...…

#HappyLearning #DevOps#Linux#UserManagement#EC2#LearningJourney#Tech#CloudComputing #ShubhamLondhe #TrainWithShubham#Linux#Ubuntu
#AWS#90daysofdevops

0
Subscribe to my newsletter

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

Written by

shailaja sutar
shailaja sutar