Where the process of the service?

0

1

At UBUNTU, service postgresql status lists

  Process: 18534 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 18534 (code=exited, status=0/SUCCESS)

but when I test sudo ps -ax | grep 18534 nothing is listed.


NOTES

EDIT1 for @DanielB request, but I need a simple command that shows any service PID.

Here a dump more /lib/systemd/system/postgresql.service,

# systemd service for managing all PostgreSQL clusters on the system. This
# service is actually a systemd target, but we are using a service since
# targets cannot be reloaded.

[Unit]
Description=PostgreSQL RDBMS

[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on

[Install]
WantedBy=multi-user.target

EDIT2

The PostgreSQL above was my localhost server... Now I am testing in a "new, clean and shine" DigitalOcean Droplet with UBUNTU 16 LTS and Postgresql 9.X...

root@myServer:~# service postgresql status
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Dom 2016-12-18 17:47:09 UTC; 2 weeks 4 days ago
 Main PID: 8703 (code=exited, status=0/SUCCESS)
    Tasks: 0
   Memory: 0B
      CPU: 0
   CGroup: /system.slice/postgresql.service

Dez 18 17:47:09 myServer systemd[1]: Starting PostgreSQL RDBMS...
Dez 18 17:47:09 myServer systemd[1]: Started PostgreSQL RDBMS.
Dez 18 17:47:14 myServer systemd[1]: Started PostgreSQL RDBMS.


root@myServer:~# sudo ps -ax | grep  8703
 3702 pts/0    S+     0:00 grep --color=auto 8703

root@myServer:~# sudo service postgresql restart

root@myServer:~# sudo ps -ax | grep  8703
 3760 pts/0    S+     0:00 grep --color=auto 8703


root@myServer:~# service postgresql status
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Sex 2017-01-06 16:06:07 UTC; 8s ago
  Process: 3755 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 3755 (code=exited, status=0/SUCCESS)

Jan 06 16:06:07 myServer systemd[1]: Starting PostgreSQL RDBMS...
Jan 06 16:06:07 myServer systemd[1]: Started PostgreSQL RDBMS.


sudo ps -ax | grep  3755
 3780 pts/0    S+     0:00 grep --color=auto 3755

Peter Krauss

Posted 2017-01-06T14:48:16.077

Reputation: 105

Well, /bin/true is obviously not the service. It’s also marked as exited. Please provide the contents of /lib/systemd/system/postgresql.service. – Daniel B – 2017-01-06T14:56:07.780

Hi @DanielB, I Edited with the dump. – Peter Krauss – 2017-01-06T15:03:07.643

For other service, as service postfix status it is ok (!). The problem with PostgreSQL is perhaps a kind of "thread activation"... Perhaps I need the service in use at top, is it? – Peter Krauss – 2017-01-06T15:06:55.747

“I need a simple command that shows any service PID.” – That’s probably not going to happen. That being said, what the f is this. – Daniel B – 2017-01-06T15:07:29.703

1It seems to me that postgresql is not running. Processes have exit code after they exited, it makes no sense to mention exit code of a currently running process. – janos – 2017-01-06T15:22:42.113

1@janos This service does obviously not start PostgreSQL. It is part of some sort of bad hack. – Daniel B – 2017-01-06T15:50:32.637

http://serverfault.com/questions/818838/postgresql-exits-after-being-started This explains what’s going on. I still think it’s bs. – Daniel B – 2017-01-06T15:56:59.833

@janos the service is alive, as I showed (and now confirm). ... I not know the behaviour of daemon (and its PIDs), perhaps we need better knowledge about it... As link above of Daniel. – Peter Krauss – 2017-01-06T16:03:51.457

@PeterKrauss you didn't show it is alive. You could try something though. What port is the service listening on? If you are on Linux (please confirm), then you can verify the port is up by running sudo netstat -ntlp | grep :the-port-number. This command will also show the process id. Include this info in your question. – janos – 2017-01-06T16:06:47.257

Thanks @janos, see my EDIT2. About port: sudo netstat -ntlp | grep 5432 shows tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 3738/postgres (for both machines). – Peter Krauss – 2017-01-06T16:14:25.493

@janos yes! you find, "LISTEN 3738/postgres" is the PID! ... sudo ps -ax | grep 3738 now returns 3738 ? S 0:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c – Peter Krauss – 2017-01-06T16:16:48.263

Answers

1

There is none, because as you can see yourself from the unit's contents, postgresql.service does not actually start any daemon. It exists merely as a 'parent' service to group together various instances of postgresql@.service (i.e. to reload all of them at once). Instead take a look at:

systemctl status postgresql@\*.service

user1686

Posted 2017-01-06T14:48:16.077

Reputation: 283 655

Perfect! Hum... But it is generic? systemctl status postfix@\*.service show nothing, despite the service postfix status show PIDs. – Peter Krauss – 2017-01-06T21:12:59.527

@PeterKrauss: They are actually two different services. postgresql@.service was explicitly named such in order to be multi-instance (see its contents), and later on, a separate postgresql.service was added to do the 'reload' trick – perhaps because back then systemctl didn't yet support the wildcards, or maybe someone just felt lazy. – user1686 – 2017-01-06T21:16:24.273

Hum.. ok (!), the syntax is systemctl status postfix.service, it works fine! So it is generic! "use systemctl instead service" is the best answer, thanks! – Peter Krauss – 2017-01-06T21:29:46.927

1

The PID of the service doesn't seem to be indicated anywhere in here:

  Process: 18534 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 18534 (code=exited, status=0/SUCCESS)

I say that because this message talks about exit code, which doesn't make sense for a running process. Only terminated processes have exit code.

If the postgres service is running, in a GNU/Linux system you can find its PID in the output of sudo netstat -ntlp | grep posgres, for example:

tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 3738/postgres

In this kind of output, 3738 is the PID.

As a side note, to verify a process by PID, instead of running ps -ax | grep the-pid, it's better to do ps -p the-pid.

janos

Posted 2017-01-06T14:48:16.077

Reputation: 2 449