How to check if a service that I don't know the name of is running on Ubuntu
Asked Answered
E

14

280

I do not know the service's name, but would like to stop the service by checking its status.

For example, if I want to check if the PostgreSQL service is running or not, but I don't know the service's name, then how could I check its status?

I know the command to check the status if the service name is known.

Endorse answered 10/9, 2013 at 14:7 Comment(4)
So how do you know it is the correct service if you don't know it's name? I can add plenty of init scripts to /etc/init.d/ with names containing keyword postgres (although this would be senseless!) and how can you know it's the service you would like to stop? Plz add some explanation for your contextSpiritoso
@Spiritoso as I am new to linux commands I would like to know if I do not know correct service name but partially using part of service name or like name can I find the sameEndorse
You may use the service lists or ps -ef and parse the outputs. Anyhow I don't think this is a good idea stopping services which you think are the ones to stop but not sure. Therefore you should make a list with the real service names running on the machine that you would like to stop. If you consider to only stop "standard" services like postgres, mysql, http you can find out the service names really easy.Spiritoso
Check askubuntu group: askubuntu.com/questions/407075/…Yepez
I
477

I don't have an Ubuntu box, but on Red Hat Linux you can see all running services by running the following command:

service --status-all

On the list the + indicates the service is running, - indicates service is not running, ? indicates the service state cannot be determined.

Interviewee answered 10/9, 2013 at 14:10 Comment(8)
Thanks. The documentation doesn't say what the symbols next to each service mean. I'd guess that "+" means it's running and "-" means it isn't... then there's the "?" next to many. + means running?Hautesavoie
"+" started "-" stopped "?" unknown sourceRiggle
How would I do this on redhat (centos)Falbala
@Falbala either chkconfig --list or service --status-all should do.Yahairayahata
Any idea why one service is marked with [-] {name} but sudo service {name} status shows as running?Pairs
You might want to run sudo initctl list as well, as mentioned by @linuxnewbee here after.Yepez
@MarkMurphy did you ever figure this out? I have a minus sign next to tomcat8 on the service listDiastrophism
@TheoF I can't recall. Sorry.Pairs
I
93

For Ubuntu (checked with 12.04)

You can get list of all services and select by color one of them with 'grep':

sudo service --status-all | grep postgres

Or you may use another way if you know correct name of service:

sudo service postgresql status
Iodometry answered 14/11, 2013 at 8:4 Comment(3)
I don't see the grep having any effect (also using Ubuntu 12.04).Jughead
The correct way to grep is: sudo service --status-all 2>&1 | grep postgresGeyserite
sudo service x status reports Active: inactive (dead) here for a running service, Ubuntu 15.04 (Vivid)Louanneloucks
C
44

Maybe what you want is the ps command;

ps -ef

will show you all processes running. Then if you have an idea of what you're looking for use grep to filter;

ps -ef | grep postgres
Cowling answered 10/9, 2013 at 14:52 Comment(2)
Sometimes the process name isn't the same as the service name.Betancourt
Probably better is pgrep -a postgres. This also avoid those annoying grep --color=auto needle.Thereabouts
H
27

There is a simple way to verify if a service is running

systemctl status service_name

Try PostgreSQL:

systemctl status postgresql
Hypso answered 8/12, 2015 at 23:38 Comment(0)
W
24

If you run the following command you will get a list of services:

sudo service --status-all

To get a list of upstart jobs run this command:

sudo initctl list
Waft answered 1/10, 2013 at 6:18 Comment(1)
@Ajay That's because Ubuntu switched from upstart to systemd on 16.10. To get the whole list I would use systemctl --full --type service --allThereabouts
H
6

You can use the below command to check the list of all services.

ps aux 

To check your own service:

ps aux | grep postgres
Heliochrome answered 7/1, 2015 at 12:24 Comment(1)
This is identical to above answerThereabouts
W
2

the best way is using of nmap tool in terminal. nmap is an useful tool that analyse an up system, using it's IP Address, then show all actived network services.

open terminal and use of this example :

~$ nmap 192.168.1.3/24

Starting Nmap 5.21 ( http://nmap.org ) at 2016-05-16 22:49 IRDT
Nmap scan report for 192.168.1.3
Host is up (0.00020s latency).
Not shown: 994 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
23/tcp   open  telnet
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
3389/tcp open  ms-term-serv
3689/tcp open  rendezvous
Wiggs answered 16/5, 2016 at 18:23 Comment(1)
This only works if its a network service, obviously.Lardaceous
A
2

run

ps -ef | grep name-related-to-process

above command will give all the details like pid, start time about the process.

like if you want all java realted process give java or if you have name of process place the name

Acus answered 21/2, 2018 at 8:23 Comment(1)
This works until service name is 8 characters or less. Otherwise, the listing is truncated.Euryale
F
2

To check the status of a service on linux operating system :

//in case of super user(admin) requires    
sudo service {service_name} status 
// in case of normal user
service {service_name} status 

To stop or start service

// in case of admin requires
sudo service {service_name} start/stop
// in case of normal user
service {service_name} start/stop 

To get the list of all services along with PID :

sudo service --status-all

You can use systemctl instead of directly calling service :

systemctl status/start/stop {service_name}
Faulkner answered 25/6, 2019 at 5:1 Comment(0)
C
1

For centos, below command worked for me (:

locate postgres | grep service

Output:

/usr/lib/firewalld/services/postgresql.xml

/usr/lib/systemd/system/postgresql-9.3.service

sudo systemctl status postgresql-9.3.service
Copalite answered 21/2, 2018 at 8:21 Comment(0)
I
0

Dirty way to find running services. (sometime it is not accurate because some custom script doesn't have |status| option)

[root@server ~]# for qw in `ls /etc/init.d/*`; do  $qw status | grep -i running; done
auditd (pid  1089) is running...
crond (pid  1296) is running...
fail2ban-server (pid  1309) is running...
httpd (pid  7895) is running...
messagebus (pid  1145) is running...
mysqld (pid  1994) is running...
master (pid  1272) is running...
radiusd (pid  1712) is running...
redis-server (pid  1133) is running...
rsyslogd (pid  1109) is running...
openssh-daemon (pid  7040) is running...
Immersionism answered 16/4, 2015 at 16:41 Comment(0)
S
0

for Centos 6.10 : /sbin/service serviceNAME status

for Centos 7.6 and ubuntu 18.04: systemctl status NAME.service

works for all of them: service --status-all

Shulamith answered 19/5, 2020 at 8:28 Comment(0)
D
0

Based on this answer on a similar topic https://askubuntu.com/a/58406
I prefer: /etc/init.d/postgres status

Dermato answered 5/6, 2020 at 12:50 Comment(0)
S
0

if you are looking particularly for postgres there is a specific command called "pgrep" you can find the usage in the below mentioned article https://mydbanotebook.org/post/troubleshooting-01/

this article provides the following details: check if postgres server is running where does postgres store all the server config how to start/stop postgres

hope this is helpful

Stock answered 25/10, 2021 at 23:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.