Skip to content

Commit

Permalink
Merge pull request #7337 from gurevichmark/mysqlsetup_mariadb_RH9
Browse files Browse the repository at this point in the history
mysqlsetup enhancements
  • Loading branch information
besawn committed Feb 17, 2023
2 parents 83b2c1a + a2440a2 commit 5f52874
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 74 deletions.
6 changes: 3 additions & 3 deletions docs/source/advanced/hierarchy/databases/mysql_remove.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ If you no longer want to use MySQL/MariaDB to maintain ``xcatdb``, and like to s

XCATBYPASS=1 restorexCATdb -p ~/xcat-dbback

* Change to PostgreSQL, following documentation: :doc:`/advanced/hierarchy/databases/postgres_install`
* To switch to PostgreSQL, follow: :doc:`/advanced/hierarchy/databases/postgres_install`


* Change back to default xCAT database, SQLite (**Note**: xCAT Hierarchy cluster will no longer work)
* To switch to default xCAT database, SQLite (**Note**: xCAT Hierarchy cluster will no longer work):

#. Stop the ``xcatd`` daemon on the management node. ::

Expand All @@ -33,7 +33,7 @@ If you no longer want to use MySQL/MariaDB to maintain ``xcatdb``, and like to s

mysql> drop user xcatadm;

#. Move, or remove, the ``/etc/xcat/cfglog`` file as it points xCAT to MySQL/MariaDB. (without this file, xCAT defaults to SQLite): ::
#. Move, or remove, the ``/etc/xcat/cfgloc`` file as it points xCAT to MySQL/MariaDB. (without this file, xCAT defaults to SQLite): ::

rm /etc/xcat/cfgloc

Expand Down
4 changes: 2 additions & 2 deletions docs/source/advanced/hierarchy/databases/postgres_remove.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ To remove ``xcatdb`` completely from the PostgreSQL database and restore xCAT da
rm -rf *
exit

#. Move, or remove, the ``/etc/xcat/cfglog`` file as it points xCAT to PostgreSQL. (without this file, xCAT defaults to SQLite): ::
#. Move, or remove, the ``/etc/xcat/cfgloc`` file as it points xCAT to PostgreSQL. (without this file, xCAT defaults to SQLite): ::

mv /etc/xcat/cfgloc /etc/xcat/cfglog.postgres
mv /etc/xcat/cfgloc /etc/xcat/cfgloc.postgres

#. Restore the PostgreSQL database into SQLite: ::

Expand Down
18 changes: 6 additions & 12 deletions docs/source/guides/admin-guides/references/man1/mysqlsetup.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ DESCRIPTION
***********


\ **mysqlsetup**\ - Sets up the MySQL or MariaDB database (linux only for MariaDB) for xCAT to use. The mysqlsetup script is run on the Management Node as root after the MySQL code or MariaDB code has been installed. Before running the init option, the MySQL server should be stopped, if it is running. The xCAT daemon, xcatd, must be running, do not stop it. No xCAT commands should be run during the init process, because we will be migrating the xCAT database to MySQL or MariaDB and restarting the xcatd daemon as well as the MySQL daemon. For full information on all the steps that will be done, read the "Configure MySQL and Migrate xCAT Data to MySQL" sections in
\ **mysqlsetup**\ - Sets up the MySQL or MariaDB database (linux only for MariaDB) for xCAT to use. The \ **mysqlsetup**\ script is run on the Management Node as root after the MySQL or MariaDB packages have been installed. Before running the \ **-**\ **-init**\ option, the MySQL server should be stopped, if it is running. The xCAT daemon, \ **xcatd**\ , must be running, do not stop it. No xCAT commands should be run during the init process, because we will be migrating the xCAT database to MySQL or MariaDB and restarting the \ **xcatd**\ daemon as well as the MySQL daemon. For more information, see https://xcat-docs.readthedocs.io/en/stable/advanced/hierarchy/databases/index.html#mysql-mariadb

\ **Setting_Up_MySQL_as_the_xCAT_DB**\

Two passwords must be supplied for the setup, a password for the xcatadmin id and a password for the root id in the MySQL database. These will be prompted for interactively, unless the environment variables XCATMYSQLADMIN_PW and XCATMYSQLROOT_PW are set to the passwords for the xcatadmin id and root id in the database,resp.
Two passwords must be supplied for the setup, a password for the xcatadmin id and a password for the root id in the MySQL database. These will be prompted for interactively, unless the environment variables \ **XCATMYSQLADMIN_PW**\ and \ **XCATMYSQLROOT_PW**\ are set to the passwords for the xcatadmin id and root id in the database,respectively.

Note below we refer to MySQL but it works the same for MariaDB.

Expand Down Expand Up @@ -72,14 +70,14 @@ OPTIONS

\ **-i|-**\ **-init**\

The init option is used to setup a xCAT database on an installed MySQL or MariaDB server for xCAT to use. The mysqlsetup script will check for the installed MariaDB server rpm first and will use MariaDB if it is installed. This involves creating the xcatdb database, the xcatadmin id, allowing access to the xcatdb database by the Management Node. It customizes the my.cnf configuration file for xcat and starts the MySQL server. It also backs up the current xCAT database and restores it into the newly setup xcatdb MySQL database. It creates the /etc/xcat/cfgloc file to point the xcatd daemon to the MySQL database and restarts the xcatd daemon using the database.
On AIX, it additionally setup the mysql id and group and corrects the permissions in the MySQL install directories. For AIX, you should be using the MySQL rpms available from the xCAT website. For Linux, you should use the MySQL or MariaDB rpms shipped with the OS. You can chose the -f and/or the -o option, to run after the init.
The \ **-**\ **-init**\ option is used to setup a xCAT database on an installed MySQL or MariaDB server for xCAT to use. The \ **mysqlsetup**\ script will check for the installed MariaDB server rpm first and will use MariaDB if it is installed. This involves creating the xcatdb database, the xcatadmin id, allowing access to the xcatdb database by the Management Node. It customizes the \ **my.cnf**\ configuration file for xcat and starts the MySQL server. It also backs up the current xCAT database and restores it into the newly setup xcatdb MySQL database. It creates the \ **/etc/xcat/cfgloc**\ file to point the xcatd daemon to the MySQL database and restarts the xcatd daemon using the database.
On AIX, it additionally setup the mysql id and group and corrects the permissions in the MySQL install directories. For AIX, you should be using the MySQL rpms available from the xCAT website. For Linux, you should use the MySQL or MariaDB rpms shipped with the OS. You can chose the \ **-f**\ and/or the \ **-o**\ option, to run after the <-**\ **-init>.


\ **-u|-**\ **-update**\

To run the update option, you must first have run the -i option and have xcat successfully running on the MySQL database. You can chose the -f and/or the -o option, to update.
To run the update option, you must first have run the \ **-i**\ option and have xcat successfully running on the MySQL database. You can chose the \ **-f**\ and/or the \ **-o**\ option, to update.



Expand All @@ -91,17 +89,13 @@ OPTIONS

\ **-o|-**\ **-odbc**\

This option sets up the ODBC /etc/../odbcinst.ini, /etc/../odbc.ini and the .odbc.ini file in roots home directory will be created and initialized to run off the xcatdb MySQL database.
See "Add ODBC Support" in
Setting_Up_MySQL_as_the_xCAT_DB
This option sets up the ODBC \ **/etc/../odbcinst.ini**\ , \ **/etc/../odbc.ini**\ and the \ **.odbc.ini**\ file in roots home directory will be created and initialized to run off the xcatdb MySQL database.



\ **-L|-**\ **-LL**\

Additional database configuration specifically for the LoadLeveler product.
See "Add ODBC Support" in
Setting_Up_MySQL_as_the_xCAT_DB



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ nodetype Attributes:

\ **os**\

The operating system deployed on this node. Valid values: AIX, rhels\*,rhelc\*, rhas\*,centos\*,rocky\*,SL\*, fedora\*, sles\* (where \* is the version #). As a special case, if this is set to "boottarget", then it will use the initrd/kernel/parameters specified in the row in the boottarget table in which boottarget.bprofile equals nodetype.profile.
The operating system deployed on this node. Valid values: AIX, rhels\*,rhelc\*, rhas\*,centos\*, alma\*, rocky\*,SL\*, fedora\*, sles\* (where \* is the version #). As a special case, if this is set to "boottarget", then it will use the initrd/kernel/parameters specified in the row in the boottarget table in which boottarget.bprofile equals nodetype.profile.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ osimage Attributes:

\ **osvers**\

The Linux operating system deployed on this node. Valid values: rhels\*,rhelc\*, rhas\*,centos\*,rocky\*,SL\*, fedora\*, sles\* (where \* is the version #).
The Linux operating system deployed on this node. Valid values: rhels\*,rhelc\*, rhas\*,centos\*,alma\*, rocky\*,SL\*, fedora\*, sles\* (where \* is the version #).



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ passwd Attributes:

\ **password**\

The default password for this type of component. On Linux, a crypted form could be provided. Hashes starting with $1$, $5$ and $6$ (md5, sha256 and sha512 respectively) are supported.
The default password for this type of component. On Linux, a crypted form could be provided for the "system" component, which will be used during initial node provisioning. Hashes starting with $1$, $5$ and $6$ (md5, sha256 and sha512 respectively) are supported.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ group Attributes:

\ **os**\ (nodetype.os)

The operating system deployed on this node. Valid values: AIX, rhels\*,rhelc\*, rhas\*,centos\*,rocky\*,SL\*, fedora\*, sles\* (where \* is the version #). As a special case, if this is set to "boottarget", then it will use the initrd/kernel/parameters specified in the row in the boottarget table in which boottarget.bprofile equals nodetype.profile.
The operating system deployed on this node. Valid values: AIX, rhels\*,rhelc\*, rhas\*,centos\*, alma\*, rocky\*,SL\*, fedora\*, sles\* (where \* is the version #). As a special case, if this is set to "boottarget", then it will use the initrd/kernel/parameters specified in the row in the boottarget table in which boottarget.bprofile equals nodetype.profile.



Expand Down
2 changes: 1 addition & 1 deletion docs/source/guides/admin-guides/references/man7/node.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ node Attributes:

\ **os**\ (nodetype.os)

The operating system deployed on this node. Valid values: AIX, rhels\*,rhelc\*, rhas\*,centos\*,rocky\*,SL\*, fedora\*, sles\* (where \* is the version #). As a special case, if this is set to "boottarget", then it will use the initrd/kernel/parameters specified in the row in the boottarget table in which boottarget.bprofile equals nodetype.profile.
The operating system deployed on this node. Valid values: AIX, rhels\*,rhelc\*, rhas\*,centos\*, alma\*, rocky\*,SL\*, fedora\*, sles\* (where \* is the version #). As a special case, if this is set to "boottarget", then it will use the initrd/kernel/parameters specified in the row in the boottarget table in which boottarget.bprofile equals nodetype.profile.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ osimage Attributes:

\ **osvers**\ (osimage.osvers)

The Linux operating system deployed on this node. Valid values: rhels\*,rhelc\*, rhas\*,centos\*,rocky\*,SL\*, fedora\*, sles\* (where \* is the version #).
The Linux operating system deployed on this node. Valid values: rhels\*,rhelc\*, rhas\*,centos\*,alma\*, rocky\*,SL\*, fedora\*, sles\* (where \* is the version #).



Expand Down
85 changes: 46 additions & 39 deletions xCAT-client/bin/mysqlsetup
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ if ($::RUNCMD_RC == 0) {
# check to see if mysql is installed
#
$cmd = "rpm -qa | grep -i perl-DBD-mysql";
my $msg = "\nMySQL perl DBD ";
my $msg = "\nperl-DBD-mysql ";
if ($::debianflag) {
if ($::MariaDB) {
$cmd = "dpkg -l | grep -i mariadb-server";
Expand All @@ -184,39 +184,41 @@ if ($::RUNCMD_RC != 0)
exit(1);
}

# check to see if MySQL is running
# check to see if MySQL or MariaDB is running
$::mysqlrunning = 0;
$::xcatrunningmysql = 0;
my $cmd = "ps -ef | grep mysqld";
my @output = xCAT::Utils->runcmd($cmd, 0);
my $mysqlcheck = "mysql.sock"; # see if really running
if (grep(/$mysqlcheck/, @output))
{

if ($::INIT)
{
my $message =
"MySQL is running. Database initialization will not take place.";
my $cmd = "pidof mysqld";
xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC == 0) {
$::mysqlrunning = 1;
if ($::INIT) {
my $message = "MySQL is already running. Database initialization will not take place.";
xCAT::MsgUtils->message("I", "$message");
my $ret = xCAT::Utils->stopservice("mysql");
if ($ret != 0) {
xCAT::MsgUtils->message("E", " failed to stop MySQL.");
exit(1);
} else {
$::mysqlrunning = 0; # service was stopped
}
}
$::mysqlrunning = 1;
}

# Stop mysql in order to setup init xcat mysql
$cmd = "pidof mysqld";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC == 0)
{
if ($::INIT)
{
my $ret = xCAT::Utils->stopservice("mysql");
if ($ret != 0)
{
xCAT::MsgUtils->message("E", " failed to stop mysql/mariadb.");
$cmd = "pidof mariadbd";
xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC == 0) {
$::mysqlrunning = 1;
if ($::INIT) {
my $message = "MariaDB is already running. Database initialization will not take place.";
xCAT::MsgUtils->message("I", "$message");
my $ret = xCAT::Utils->stopservice("mariadb");
if ($ret != 0) {
xCAT::MsgUtils->message("E", " failed to stop MariaDB.");
exit(1);
}
} else {
$::mysqlrunning = 1;
} else {
$::mysqlrunning = 0; # service was stopped
}
}
}

Expand All @@ -229,7 +231,7 @@ if (-e ("/etc/xcat/cfgloc")) # check to see if xcat is using mysql
if ($::INIT)
{
my $message =
"The /etc/xcat/cfgloc file is already configured for MySQL and xCAT is using mysql as it's database. No xCAT setup is required.";
"The /etc/xcat/cfgloc file is already configured for MySQL and xCAT is using mysql or mariadb as it's database. No xCAT setup is required.";
xCAT::MsgUtils->message("I", "$message");
}
$::xcatrunningmysql = 1;
Expand Down Expand Up @@ -436,6 +438,12 @@ if (($::INIT) && ($::xcatrunningmysql == 0))
}

} # end initialization
else {
# MySQL not running, restart it
if ($::mysqlrunning == 0) {
&mysqlstart;
}
}

if ($::SETUPODBC)
{
Expand Down Expand Up @@ -976,26 +984,25 @@ sub mysqlstart
exit(1);
}

# make sure running
$cmd = "ps -ef | grep mysqld | grep -v grep";
my $i;
for ($i = 0 ; $i < 12 ; $i++)
{
# Make sure service has started. On some OSes, mariadb service starts mysql daemon
# on others, mariadb service starts mariadb daemon. Check a few times for one,
# then the other
my $mariadb_process_name = "mariadbd";
my $mysql_process_name = "mysqld";
my $db_process_name_pattern = "\'".$mariadb_process_name."\|".$mysql_process_name."\'";
for (my $i = 0 ; $i < 6 ; $i++) {
$cmd = "ps -ef | grep -E $db_process_name_pattern | grep -v grep";
my @output = xCAT::Utils->runcmd($cmd, 0);
$mysqlcheck = "mysqld";

if (grep(/$mysqlcheck/, @output))
{
if (grep(/$mariadb_process_name/, @output) || grep(/$mysql_process_name/, @output)) {
sleep 10; # give a few extra seconds to be sure
return;
}
else
{
} else {
sleep 10; # wait for daemon
}
}
xCAT::MsgUtils->message("E",
" Could not start the mysql daemon, in time allocated (2 minutes)");
" Could not start the mysql/mariadb daemon in time allocated (1 minute)");
exit(1);

}
Expand Down

0 comments on commit 5f52874

Please sign in to comment.