🔛Starting and Stopping Services

  1. Starting Services:

    • sudo service apache2 start:

      • Explanation: Starts the Apache web server service.

      • Example: Running sudo service apache2 start would initiate the Apache web server and make it available for serving web pages.

    • python3 -m http.server 80:

      • Explanation: Starts a simple HTTP server using Python on port 80.

      • Example: Running python3 -m http.server 80 would start a basic HTTP server on port 80, allowing you to serve files from the current directory.

  2. Stopping Services:

    • sudo service apache2 stop:

      • Explanation: Stops the Apache web server service.

      • Example: Running sudo service apache2 stop would halt the running Apache web server, shutting down any active web page serving.

  3. Enabling and Disabling Services on System Boot:

    • sudo systemctl enable ssh:

      • Explanation: Enables the SSH (Secure Shell) service to start automatically on system boot.

      • Example: Running sudo systemctl enable ssh would configure the system to start the SSH service during system startup.

    • sudo systemctl disable ssh:

      • Explanation: Disables the SSH service from starting automatically on system boot.

      • Example: Running sudo systemctl disable ssh would prevent the SSH service from starting automatically during system startup.

  4. Checking the Status of Services:

    • sudo service apache2 status:

      • Explanation: Displays the current status of the Apache web server service.

      • Example: Running sudo service apache2 status would show whether the Apache service is running, stopped, or encountering issues.

    • sudo systemctl status ssh:

      • Explanation: Displays the current status of the SSH service.

      • Example: Running sudo systemctl status ssh would provide information about the status of the SSH service, including whether it's active or inactive.

Starting and Stopping Services:

  • sudo service apache2 restart:

    • Explanation: Restarts the Apache web server service.

    • Example: Running sudo service apache2 restart would stop and then start the Apache web server, applying any configuration changes.

  • sudo systemctl start serviceName:

    • Explanation: Starts a service using systemd.

    • Example: Running sudo systemctl start apache2 would start the Apache web server using systemd.

  • sudo systemctl stop serviceName:

    • Explanation: Stops a service using systemd.

    • Example: Running sudo systemctl stop apache2 would stop the running Apache web server.

Enabling and Disabling Services:

  • sudo service apache2 enable:

    • Explanation: Enables the Apache web server service to start on boot.

    • Example: Running sudo service apache2 enable would configure Apache to start automatically during system startup.

  • sudo service apache2 disable:

    • Explanation: Disables the Apache web server service from starting on boot.

    • Example: Running sudo service apache2 disable would prevent Apache from starting automatically during system startup.

  • sudo systemctl is-enabled serviceName:

    • Explanation: Checks if a service is enabled to start on boot using systemd.

    • Example: Running sudo systemctl is-enabled apache2 would indicate whether Apache is set to start on boot.

Checking Service Logs:

  • journalctl -u serviceName:

    • Explanation: Displays the logs for a specific service.

    • Example: Running journalctl -u apache2 would show logs related to the Apache web server.

Reloading Service Configuration:

  • sudo systemctl reload serviceName:

    • Explanation: Reloads the configuration of a running service without stopping it.

    • Example: Running sudo systemctl reload apache2 would reload the configuration of the Apache web server.

Last updated