How to check if a particular service is running on Ubuntu

前端 未结 13 1896
猫巷女王i
猫巷女王i 2021-01-29 17:48

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 no

相关标签:
13条回答
  • 2021-01-29 17:55

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

    systemctl status service_name
    

    Try PostgreSQL:

    systemctl status postgresql
    
    0 讨论(0)
  • 2021-01-29 17:57

    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...
    
    0 讨论(0)
  • 2021-01-29 18:01

    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
    
    0 讨论(0)
  • 2021-01-29 18:01

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

    ps aux 
    

    To check your own service:

    ps aux | grep postgres
    
    0 讨论(0)
  • 2021-01-29 18:01

    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
    
    0 讨论(0)
  • 2021-01-29 18:04

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

    0 讨论(0)
提交回复
热议问题