LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   systemctl status postgresql-tst.service starts the service if service is stopped (https://www.linuxquestions.org/questions/linux-newbie-8/systemctl-status-postgresql-tst-service-starts-the-service-if-service-is-stopped-4175641634/)

MarianForums 11-02-2018 05:35 AM

systemctl status postgresql-tst.service starts the service if service is stopped
 
Hi,

I'm running postgresql 9.6 on a Red Hat 7 system and have created my own service script to start and stop the instance(-s).
When I run systemctl stop postgresql-tst.service the service is stopped as expected. But when I run systemctl status postgresql-tst.service is starts it up again. That is not what I want: I just want it to give me the status which is stopped. Can someone tell me if this is expected behaviour on Red Hat 7?

Thanks in advance.
Regards,
Marian

berndbausch 11-02-2018 09:29 AM

systemctl status should display the status, not start the service. The behaviour you observe is not expected.

If you want help to understand why it behaves like this, share the service definition.

By the way, Red Hat 7 is very old and doesn’t use systemd. I suspect you run RHEL 7.

MarianForums 11-02-2018 10:50 AM

Hi,

This is what my service script looks like:
cat /usr/lib/systemd/system/postgresql-tst.service
[Unit]
Description=postgresql_postgres-tst
After=syslog.target
After=network.target

[Service]
Type=forking
User=postgres
Group=postgres
Environment=PGDATA=/data/postgres-tst/data-01/
# Run ExecStartPre with root-permissions
PermissionsStartOnly=true
ExecStartPre=/bin/chown postgres:postgres /var/run/postgresql

ExecStart=/usr/pgsql-9.6/bin/pg_ctl start -D ${PGDATA}
ExecStop=/usr/pgsql-9.6/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/pgsql-9.6/bin/pg_ctl reload -D ${PGDATA} -s
Restart=on-failure
KillMode=control-group
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s

[Install]
WantedBy=multi-user.target

Thanks in advance.
regards
Marian

berndbausch 11-02-2018 06:13 PM

Hmmm I don’t see a problem. Though admittedly I don’t know whether the PostgreSQL commands are correct.

What makes you think the systemctl status command starts the service, and not something else? What do you see in the service’s journal?

By the way, please use code tags to format code and command output so that it’s readable. See my signature.

ondoho 11-03-2018 04:34 AM

Quote:

Originally Posted by MarianForums (Post 5921992)
But when I run systemctl status postgresql-tst.service is starts it up again.

this is near impossible - unless your systemctl binary is masked by something of the same name in $HOME/bin, for example.
you must have misunderstood something, or simple typed it wrong.

scasey 11-03-2018 10:26 AM

Are you sure it's not just restarting when it is stopped? I note this:
Code:

Restart=on-failure
If that's happening, a stop followed by a status would show it was running...

berndbausch 11-03-2018 02:41 PM

Quote:

Originally Posted by scasey (Post 5922452)
Are you sure it's not just restarting when it is stopped? I note this:
Code:

Restart=on-failure
If that's happening, a stop followed by a status would show it was running...

The man page says
Quote:

the service will not be restarted if (...) the service is stopped with systemctl stop or an equivalent operation.

scasey 11-03-2018 03:02 PM

Quote:

Originally Posted by berndbausch (Post 5922525)
The man page says...

Ahh. I'm still learning 'bout systemd...

Thank you.


All times are GMT -5. The time now is 05:21 PM.