0

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) ...

[Unit]
Description=NodeService nodejs server

[Service]
User=rails
Group=rails
ExecStart=/home/rails/myrailssite_production/NodeService/start.sh
ExecStop=/home/rails/myrailssite_production/NodeService/stop.sh
Type=forking
RemainAfterExit=yes
After=postgresql-9.6.service

[Install]
WantedBy=multi-user.target

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.

0

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 Jun 11 '18 at 18:16
  • Yes, but why do you need to restart postgre? – Vikash Kesarwani Jun 11 '18 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.