I have a systemd path unit, which watches a config file to apply db changes if the config file changes. To ensure the path unit runs after mysql, I added these lines:
Wants=mysqld.service
After=mysqld.service
Requires=mysqld.service
ConditionPathExists=/run/mysql/mysql.sock
Despite all these, the path unit starts sometimes before mysql is running, I see these in the path status:
Condition: start condition failed at ...; 40s ago
└─ ConditionPathExists=/run/mysql/mysql.sock was not met
And these in the corresponding service, which is doing the updates with the mysql command:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysql/mysql.sock' (2)
The system is a custom linux setup with buildroot.
/usr/bin/mysqld_safe --log-error=/var/log/mysql/mysqld.log
mysql --version
:
mysql Ver 15.1 Distrib 10.3.36-MariaDB, for Linux (x86_64) using readline 5.1
How can I ensure mysql is running before the path unit starts watching the config file?
ExecStart=
, there is noType=
Type=notify
was added after that: github.com/buildroot/buildroot/commit/…ConditionPathExists=
should prevent the service from starting at all if the path doesn't exist (yet), which means you shouldn't see condition failed and the connection error at the same time...