How to Manage Services in Ubuntu

In this blog post, you’ll learn how to manage services in Ubuntu.

You will learn how to use the service and systemctl commands to manage and monitor services in Ubuntu.

Difference between service and systemctl

service is an “high-level” command used for starting and stopping services in different unixes and linuxes.

Depending on the “lower-level” service manager, service redirects on different binaries.

service is adequate for basic service management, while directly calling systemctl gives greater control options.

How to use service in Ubuntu

  • sudo service apache2 stop: Stops the service. Not persistent after reboot.
  • sudo service apache2 start: Starts the service. Not persistent after reboot.
  • service apache2 status: Tells you the STATUS of the service, if it is either enabled/running or disabled/NOT running.
  • sudo service apache2 restart: Restarts the service. It does a stop and start of the service.
  • sudo service apache2 reload: Keeps the service running but it just reloads the configuration.
  • sudo service apache2: In this case, since you did not mention the ACTION to execute for the service, it will show you all options available for that specific service. For other services like networking service it would mention the small list of all options available.
  • sudo service –status-all: lists all services if they are enabled or not.
  • sudo service –help: gives you help about the service command usage.

How to use systemctl in ubuntu

  • sudo systemctl start SERVICE: Use it to start a service. Does not persist after reboot.
  • sudo systemctl stop SERVICE: Use it to stop a service. Does not persist after reboot.
  • sudo systemctl restart SERVICE: Use it to restart a service.
  • sudo systemctl reload SERVICE: If the service supports it, it will reload the config files related to it without interrupting any process that is using the service.
  • systemctl status SERVICE: Shows the status of a service. Tells whether a service is currently running.
  • sudo systemctl enable SERVICE: Turns the service on, on the next reboot or on the next start event. It persists after reboot.
  • sudo systemctl disable SERVICE: Turns the service off on the next reboot or on the next stop event. It persists after reboot.
  • sudo systemctl is-enabled SERVICE: Check if a service is currently configured to start or not on the next reboot.
  • sudo systemctl is-active SERVICE: Check if a service is currently active.
  • sudo systemctl show SERVICE: Show all the information about the service.
  • sudo systemctl mask SERVICE: Completely disable a service by linking it to /dev/null; you cannot start the service manually or enable the service.
  • sudo systemctl unmask SERVICE: Removes the link to /dev/null and restores the ability to enable and or manually start the service.

I hope this was helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *