On my laptop, I use MySQL and PostgreSQL only for testing. I do not need them up until I start programming, which might be hours after startup. But starting the services manually and typing in my sudo password is a (minor) annoyance.

I read that systemd supports starting services only when the port for that service is accessed. But a quick Google search seems to indicate that socket-based activation is not yet supported in PG & MySQL.

I realize I can hack this using shell scripts or wait for the maintainers to fix the services, but I am looking for a better way now (for educational purposes).

The Question: How can I achieve on-demand startup of such services in a way that either utilizes systemd features or is recommended as a Linux "best practice"?

Some thoughts:

  • Is there a service I can install that handles auto-starting and auto-stopping services based on conditions (such as a particular process running)?
  • Is there a proxy service that gets activated by a socket and in turn launches the target service?

systemd 229, Kubuntu 16.04, MySQL 5.7, PostgreSQL 9.5

Update: The Answer:

How I used systemd-socket-proxyd as suggested by Siosm:


port        = 13306






# note: this path may vary

Reload/ stop/ start as needed:

sudo systemctl daemon-reload
sudo systemctl enable proxy-to-mysql.socket
sudo systemctl start proxy-to-mysql.socket
sudo systemctl stop mysql.service  # for testing


sudo systemctl status proxy-to-mysql.socket # should be ACTIVE
sudo systemctl status proxy-to-mysql # should be INACTIVE
sudo systemctl status mysql # should be INACTIVE
telnet 3306
sudo systemctl status proxy-to-mysql # should be ACTIVE
sudo systemctl status mysql # should be ACTIVE

You may use the systemd-socket-proxyd tool. See systemd-socket-proxyd(8) for examples.

|improve this answer|||||

socket-based activation is not yet supported in PostgreSQL & MySQL.

The question is the answer. You have already found the better way, mentioned it in the question, and then stated that it has not been implemented. Oracle closed the issue saying that socket activation (really, using already-opened listening file descriptors instead of opening its own, as far as the server program is concerned) has been implemented when it has not been. MariaDB has a still-open issue. As for PostgreSQL, you are in the same boat as Christoph Berg waiting for this to be implemented.

Further reading

|improve this answer|||||
  • Thank you, but the whole point of my question is to figure out how to achieve this now, for any such services. I will clarify this in my question. – Oleg Mar 20 '17 at 0:14

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.