Chapter 1.3 : A simple script
This section present a very simple script, which can be executed manually, at boot time or any other time you deem useful. ;)
Its (untested) purpose is to setup an MySQL Server and import a base sql file from a repository to load it into the database.
// User->Create IS idempotent
$User->Create("_mysql",null,"MySQL Daemon",null,null,"mysql","/var/mysql","/sbin/nologin")
if (! $File->Exists("/var/mysql")) {
$File->Makedir("/var/mysql","0770","_mysql","_mysql");
}
// we can also rely on Makedir's idempotency with the following:
$File->Makedir("/var/mysql_logs","0770","_mysql","_mysql");
// install the package
if ( $Package->Install("mysql-server") ) {
/**
* Setup the base db
* need to start the DB first (maybe on Linux it does it at install-time?)
*/
$Service->Setup("mysqld","_mysql");
$Service->Start("mysqld");
// transfer a database source from a repository
// but let's be idempotent about it; make sure its not already loaded
if (! $File->Exists("/var/mysql/node_xxx.db") ) {
if ( $File->Source("user@server:databases/node_xxx.sql","./") ){
if ($File->Run_Process("mysql -u root -p$password < ./node_xxx.sql") ) {
print "Database successfully installed!\n";
}
}
}
}