LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-02-2018, 05:35 AM   #1
MarianForums
LQ Newbie
 
Registered: Nov 2018
Posts: 2

Rep: Reputation: Disabled
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
 
Old 11-02-2018, 09:29 AM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,087

Rep: Reputation: 809Reputation: 809Reputation: 809Reputation: 809Reputation: 809Reputation: 809Reputation: 809
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.
 
Old 11-02-2018, 10:50 AM   #3
MarianForums
LQ Newbie
 
Registered: Nov 2018
Posts: 2

Original Poster
Rep: Reputation: Disabled
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 postgresostgres /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
 
Old 11-02-2018, 06:13 PM   #4
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,087

Rep: Reputation: 809Reputation: 809Reputation: 809Reputation: 809Reputation: 809Reputation: 809Reputation: 809
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.

Last edited by berndbausch; 11-02-2018 at 06:14 PM.
 
Old 11-03-2018, 04:34 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 11,771
Blog Entries: 9

Rep: Reputation: 3142Reputation: 3142Reputation: 3142Reputation: 3142Reputation: 3142Reputation: 3142Reputation: 3142Reputation: 3142Reputation: 3142Reputation: 3142Reputation: 3142
Quote:
Originally Posted by MarianForums View Post
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.
 
Old 11-03-2018, 10:26 AM   #6
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,233

Rep: Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104
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...
 
Old 11-03-2018, 02:41 PM   #7
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,087

Rep: Reputation: 809Reputation: 809Reputation: 809Reputation: 809Reputation: 809Reputation: 809Reputation: 809
Quote:
Originally Posted by scasey View Post
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.
 
Old 11-03-2018, 03:02 PM   #8
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,233

Rep: Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104Reputation: 1104
Quote:
Originally Posted by berndbausch View Post
The man page says...
Ahh. I'm still learning 'bout systemd...

Thank you.

Last edited by scasey; 11-03-2018 at 03:04 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables neither systemctl or service starts it richard-g8jvm2 Linux - Security 5 09-14-2018 05:00 PM
Problem with MySQL install on virt CentOS,no /var/lib/mysql/mysql.sock , systemctl start mysqld.service dont run the service Positive1 CentOS 1 08-13-2016 03:33 AM
Job for vncserver@:1.service failed. See 'systemctl status vncserver@:1.service' and anis123 Linux - Server 0 09-16-2015 08:44 AM
NAGIOS: Name or service not known output returned for custom developed service status katsanterre Linux - Software 2 05-07-2013 08:55 AM
Cron service and oracle service stopped unexpectedly. Can't restart oracle. camron Linux - Newbie 6 06-10-2010 06:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration