Skip to content

Instantly share code, notes, and snippets.

@reveng007
Last active May 26, 2021 15:41
Show Gist options
  • Save reveng007/4cba211f4f53a76e06ddb202e381cd5b to your computer and use it in GitHub Desktop.
Save reveng007/4cba211f4f53a76e06ddb202e381cd5b to your computer and use it in GitHub Desktop.

1. sudo /etc/init.d/apache2 status

2. sudo service apache2 status

3. sudo systemctl status apache2.service

All this 3 commands apparently produced same output, but there is a difference among them...

ANS:

service operates on the files in /etc/init.d and was used in conjunction with the old init system. systemctl operates on the files in /lib/systemd. If there is a file for your service in /lib/systemd it will use that first and if not it will fall back to the file in /etc/init.d. Also If you are using OS like ubuntu-14.04 only service command will be available, as systemd is introduced recently to the linux world.

So if systemctl is available ,it will be better to use it
see: stackoverflow -> https://bit.ly/3aaJYhz

1. What is init.d ?

ANS:

init.d is deamon which is the first process of the Linux system. Then other processes, services, daemons, and threads are started by init. So init.d is a configuration database for the init process.

A daemon (also known as background processes) is a Linux or UNIX program that runs in the background. Almost all daemons have names that end with the letter "d". For example, httpd the daemon that handles the Apache server, or, sshd which handles SSH remote access connections. Linux often start daemons at boot time. Shell scripts stored in /etc/init.d directory are used to start and stop daemons.

2. what is "service" in "sudo service apache2 status" ?

ANS:

service "service name" start/stop/status/restart

In this simple manner, we are using service management in Linux but what actually happens and how it actually works in the background, is that all these service works on several scripts and these scripts are stored in /etc/init.d location.

The Story Behind ‘init’ and ‘systemd’: Why ‘init’ Needed to be Replaced with ‘systemd’ in Linux

If somehow init daemon could not start, no process will be started and the system will reach a stage called “Kernel Panic“.

3. What is "systemctl" in "systemctl status apache2.service" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment