0

I am installing Postgres on CentOS 7 boxes, and that part itself is fine. The issue that someone brought up is that they would like for my install script to try and not depend on the service name being postgresql-10, and instead just use postgres or postgresql. Either one would be fine. Well I noticed that there is a flag --servicename that can be used, but I am unsure where to use it in the process. I have tried a few times but it doesn't seem to work.

Note that this is how I am installing postgres

yum -y install $LINK
yum -y install postgresql10
yum -y install postgresql10-server
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10

the $LINK up there is just the path to pull from the Postgres website. Again, the ideal situation would be for me to specify the service name such that I can standardize that and limit script changes when Postgres versions change.

Note that I found out about the --servicename flag in this, link but I am not completely sure how to apply that to the installation above. It does appear that the link is more for installing on windows, but I would assume we could do the same thing in a Linux installation. Any suggestions here would be welcome.

2
  • You can install it as is and change the servicename later at anytime in /usr/lib/systemd/system/postgresql.service and run postgresql under foobareatsbarfoodbarefoot if u like by defining the [UNIT] and WorkingDirectory, ExecStart, Log etc.. Commented Feb 11, 2019 at 15:24
  • Right, I mean I know that works, I was trying to find a better way than doing that. Commented Feb 11, 2019 at 15:38

1 Answer 1

1

The link that you found is about EnterpriseDB's installer for Windows, and the service mentioned is a Windows service. That won't help you on CentOS.

The name of the systemd service file is hard-wired into the RPM, but there is nothing that prevents you from creating your own service file in /etc/systemd/system and using that one instead. Then you can choose whatever name you prefer. You can just copy the service file from the RPM as a starting point.

Renaming the file or creating one in /usr/systemd/system is not a good idea, because that will mess with RPMs.

postgresql-10 is a good name for the service, however. If you choose postgres or something else that doesn't contain the version, what will you do once you want to install v11?

To answer your question: There is no way to configure the name of the service when installing it via RPM.

Sign up to request clarification or add additional context in comments.

5 Comments

Right, I am aware that is for windows, I was more or less asking if there is someway from command line to do the same thing in linux. The reason we want it to change is stated above, Its so that when future versions come out I won't have to change as much about the script if possible. At least that is what has been requested. So if we can just make the service postgresql instead of it being version dependent then thats one less area we would have to modify.
There is no way to configure the name of the service in an RPM installation.
you could mess with the service name via bash-commands or scripts invoked on startup after installation ( schlechte idee/bad idea) but not while installation as @LaurenzAlbe stated
I assume there is a better way to do this but if there isn't, then thats fine and I can leave it as postgresql-10 . Personally I am fine with that as I can make some minor changes when we moved things to version 11.
You will want to have both versions installed when you upgrade.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.