Context: MySQL server deployed with MysqldResource java class (Connector/MXJ lib). They app using mysql server may crash for some reason and could be finished without shutting down the MySQL.
The setup and run of MySQL done as following:
mr = new MysqldResource(runtimeDir, dataDir);
mr.start("My MySQL", options);
Goal: Write code to ensure that MySQL is not running (MysqldResource.pid doesn’t exist, or pid doesn’t exist). If MySQL I would like to kill it.
Note: I am not going to start mysqld!
Finally,
How do I archieve the Goal using MysqldResource interface, is it even possible? Or I should workout with .pid file for that manually?
In particular will the following code work correctly for me:
mr = new MysqldResource(runtimeDir, dataDir);
mr.shutdown();
assuming its running after in another session after program crashed and without starting mysql first? In other words, will this code kill existing MySQL instance running?
The following code will work:
It works even if it’s running on another VM or with another mr instance. Also following method can be used to check if the MySQL deployed is running:
To proof that shutdown also works even if called on newly created mr instance check the shutdown code – it uses pidFile() to check the existence of process: