I'm using CentOS 7. I have a nodeJS server I want to run as a service, but I would prefer the service started after my PostGres 9.6 server had booted. I tried specifying after in my service description (/usr/lib/systemd/system/nodesrv.service) ...

Description=NodeService nodejs server



However, I think PostGres still needs a few seconds to boot up because I see this in the output for the above service

[rails@server ~]$ sudo journalctl -u nodesrv
[sudo] password for rails: 
-- Logs begin at Mon 2018-06-11 11:08:17 EDT, end at Mon 2018-06-11 11:09:40 EDT. --
Jun 11 11:08:17 server systemd[1]: Starting NodeService nodejs server...
Jun 11 11:08:17 server start.sh[124]: psql: could not connect to server: No such file or directory
Jun 11 11:08:17 server start.sh[124]: Is the server running locally and accepting
Jun 11 11:08:17 server start.sh[124]: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Is there a way to specify not to run the script until PostGres is up and running? I realize there might be circumstances in which PostGres fails to boot at all in which case I'm fine with never running the service.

1 Answer 1


You can use ExecStartPost in your postgre service, which can trigger the start of your service or you can use ExecStartPre in your service which can check for postre service before it executes ExecStart

  • Would this run my service every time PostGre starts?
    – Dave
    Commented Jun 11, 2018 at 18:16
  • Yes, but why do you need to restart postgre? Commented Jun 11, 2018 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .