Systemd Service with Dependency

Ubuntu 20.04

I added a php script to Systemd Services. The script builds a large 2 GB memory database. The problem is that if running the script at startup, only half of the tables are created. Otherwise running the script AFTER startup works fine. I figured out that that problem is that my php script runs before MYSQL server has finished its booting.

So I added a 30 sec delay before my scripts start running. That works, but is there a more professional solution? The script should detect if MYSQL server is already running, and immediately after that should my Systemd Service start.

Is there a way to do that?

Thank you for your reply. I tried that code, but not working.
To start my php script after mysql server has finished booting, I tried this one:

[Unit]
Description=memory_tables_import

[Service]
ExecStart=php /home/xxx/public_html/memory_tables_import.php
Requires=mysql.service
After=mysql.service

[Install]
WantedBy=multi-user.target

What is wrong?

Should the “After” part go to the [Unit] section?

[Unit]
Description=memory_tables_import
After=syslog.target network.target mysql.service

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.