In this post I will show you some quick and easy ways to show all services that are running, as-well as how to stop, start, restart, checking service status, enabling/disabling services during startup, and finding service related processes. I will be using apache2 as my go to for this example but you can simply substitute apache2 with whatever service suits your needs.
Some Linux distributions will give you a confirmation message when you start/stop/restart a service, some will simply do it. If you need a confirmation message but don’t get one you can simply add “&& echo Success” to the end of the command. The distribution I am using for example will not give a message so this is what I am doing for the purpose of this guide.
Check if Service is Running
service apache2 status
service apache2 restart
service apache2 stop
service apache2 start
List All Running Services
Searching For Service Related Processes
A quick and easy way to do this is by using the ps command and piping it into a grep. To avoid false positives you can wrap the first letter of the service in brackets . This will prevent your grep from showing up in the results.
ps aux | grep [a]pache2
Enabling/Disabling Services During Startup
To enable/disable a service during startup for example starting apache2 whenever the system reboots, you will use chkconfig command. In the example below I will set apache to start during boot. To disable a service on startup simply replace enable with disable. You can check if a service is enabled during startup by running chkconfig is-enabled servicename.
chkconfig apache2 enable
Thanks for reading, if you liked this post or if I forgot anything then please feel free to comment!