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

2 Answers 2


You may use the systemd-socket-proxyd tool to forward traffic from a local socket to MySQL or PostgreSQL with socket-activation. See systemd-socket-proxyd(8) for examples, and read this SO reply for a concrete example for --user systemd.


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

  • 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. Mar 20, 2017 at 0:14
  • Mariadb now supports socket activation. It is currently only available in the alpha release 10.6.0 that was released 26 Apr 2021. The Jira issue MDEV-5536 is now marked as fixed May 16, 2021 at 12:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .