0

I have an openvpn tunnel which runs an --up script which queries a local mysql database for IP routing information and then applies the routes. However, since both the openvpn and mysql systemd services are configured with the After=network.target directive, I have a race condition: /var/run/mysqld/mysqld.sock might exist when the --up script runs, or it might not. If the sock file doesn't exist, then my script dies and the system doesn't initialize properly.

I thought that changing my openvpn.service directive to After=network.target mysql.service and running systemctl daemon-reload would do the trick. However, I added ls -lh /var/run/mysqld/mysqld.sock to the beginning of my --up script, and it still sometimes reports ls: cannot access '/var/run/mysqld/mysqld.sock': No such file or directory.

My guess is that systemd's is not using the sock file to determine whether or not mysqld has finished loading but rather some criteria that happens before the sock file is created.

Is there a way to tell systemd to not recognize mysql.service as having started until the sock file has been created?

3
  • Of course, I could start my script with a wait loop which checks for the sock file and sleeps repeatedly until it has been created, but that sounds like a hack especially if systemd can be configured to do it for me. – Isaac Sutherland Dec 14 '17 at 21:06
  • From what source did you install MySQL? – Michael Hampton Dec 14 '17 at 22:19
  • A wait loop is probably your best option on the user side. I did briefly explore the possibility of starting the socket before starting MySQL but I can't see evidence that it would work. – Simon Greenwood Dec 15 '17 at 11:18
1

i had the same problem, start some other service after mysql started

First i disable my service

systemctl disable rfid-server

After that i modified my rfid-server.service file

[Unit]
Description=rfid server
After=mysql.service

[Service]
ExecStart=/opt/rfid-server-service/deploy/start.sh

[Install]
WantedBy=multi-user.target mysql.service

An the i re-enable my service

systemctl enable /complete/path/to/service

Created symlink from /etc/systemd/system/multi-user.target.wants/rfid-server.service to /opt/rfid-server-service/rfid-server.service.
Created symlink from /etc/systemd/system/mysql.service.wants/rfid-server.service to /opt/rfid-server-service/rfid-server.service.
Created symlink from /etc/systemd/system/rfid-server.service to /opt/rfid-server-service/rfid-server.service.

As you can see, it create the symlink to mysql.service.wants

0

May be you should add ConditionPathExists check in your service file?

There is quote from systemd documentation:

With ConditionPathExists= a file existence condition is checked before a unit is started. If the specified absolute path name does not exist, the condition will fail. If the absolute path name passed to ConditionPathExists= is prefixed with an exclamation mark ("!"), the test is negated, and the unit is only started if the path does not exist.

1

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.