diff --git a/libraries/task.py b/libraries/task.py index eb7dd37..a7a45e7 100644 --- a/libraries/task.py +++ b/libraries/task.py @@ -13,7 +13,7 @@ class Task: #($server='', $ssh_user='root', $ssh_key_priv='./ssh/id_rsa', $ssh_key_password='', $ssh_path='leviathan', $mysql_conn=false) - def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='leviathan', task_id=0, data={}): + def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}): self.config=config_task diff --git a/scripts/servers/databases/mariadb/install_mariadb.py b/scripts/servers/databases/mariadb/install_mariadb.py new file mode 100644 index 0000000..043ba30 --- /dev/null +++ b/scripts/servers/databases/mariadb/install_mariadb.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +import sys +import subprocess +import argparse +import platform +import distro + +pyv=platform.python_version_tuple() + +if pyv[0]!='3': + print('Need python 3 for execute this script') + sys.exit(1) + +parser = argparse.ArgumentParser(description='Script for create a new mariadb server.') + +parser.add_argument('--password', help='The password of the new server', required=True) + +args = parser.parse_args() + +linux_distro=distro.id() + +#Dash, the default debian stretch shell, don't support <<< + +#sudo debconf-set-selections <<< 'mariadb-server mariadb-server/root_password password your_password' +#sudo debconf-set-selections <<< 'mariadb-server mariadb-server/root_password_again password your_password' + +print('Installing MariaDB...') + +if linux_distro=='debian': + + if subprocess.call("sudo DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install mariadb-server", shell=True) > 0: + print('Error, cannot install MariaDB...') + sys.exit(1) + elif linux_distro=='arch': + if call("sudo pacman -S --noconfirm mariadb", shell=True) > 0: + print('Error, cannot install MariaDB...') + exit(1) + +print('Setting the password...') + +if subprocess.call("sudo mysqladmin -u root password "+args.password, shell=True) > 0: + print('Error, cannot set the MariaDB Root password') + sys.exit(1) +else: + print('Mariadb installed successfully') + sys.exit(0) + +""" +if subprocess.call("sudo echo 'mariadb-server mariadb-server/root_password_again password "+args.password+"' | sudo debconf-set-selections", shell=True) > 0: + print('Error, cannot set the password again') + sys.exit(1) +""" + +print('Setted the password') diff --git a/scripts/system/install_pzoo_stats.py b/scripts/system/install_pzoo_stats.py index 8c3ee93..cfe5168 100644 --- a/scripts/system/install_pzoo_stats.py +++ b/scripts/system/install_pzoo_stats.py @@ -19,6 +19,7 @@ parser.add_argument('--url_stats', help='The url where pastafaristats notify the parser.add_argument('--user', help='The user for pastafari', required=True) parser.add_argument('--pub_key', help='The pub key used in pastafari user', required=True) parser.add_argument('--group', help='Server group', required=False) +parser.add_argument('--path', help='A path used for save internal things for pastafari', required=True) args = parser.parse_args() @@ -98,9 +99,11 @@ if check_url.match(args.url_stats): #su - $USER -s /bin/bash -c "composer --working-dir=$HOME/scripts require guzzlehttp/guzzle:~6.0" - #pt=Path('/home/'+args.user+'/pzoo/tasks') + args.path=os.path.basename(args.path) - #pt.mkdir(mode=0o755, parents=True, exist_ok=True) + pt=Path('/home/'+args.user+'/'+args.path+'/tasks') + + pt.mkdir(mode=0o755, parents=True, exist_ok=True) # Create scripts pzoo """ diff --git a/tasks/servers/databases/info.cfg b/tasks/servers/databases/info.cfg new file mode 100644 index 0000000..7342ecb --- /dev/null +++ b/tasks/servers/databases/info.cfg @@ -0,0 +1,8 @@ +[info] +name=Database servers +description=Install databases daemon in server standalone, for example mysql or postgres + +[modules] +mysql/standalone_mysql=Standalone mysql server, MySQL is the most famous database sql server in the web + + diff --git a/tasks/servers/databases/mysql/__init__.py b/tasks/servers/databases/mysql/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tasks/servers/databases/mysql/standalone_mysql.py b/tasks/servers/databases/mysql/standalone_mysql.py new file mode 100644 index 0000000..4a8ce58 --- /dev/null +++ b/tasks/servers/databases/mysql/standalone_mysql.py @@ -0,0 +1,86 @@ +#/usr/bin/env python3 + +from modules.pastafari2.libraries.task import Task +#from modules.pastafari.models.tasks import TaskModel +from paramecio2.libraries.db import coreforms +from paramecio2.libraries.formsutils import show_form +from collections import OrderedDict + +class ServerTask(Task): + + def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}): + + super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data) + + self.name_task='MariaDB installation' + + self.description_task='Installation of a standalone mysql server' + + self.codename_task='standalone_mysql' + + self.files=[['modules/pastafari2/scripts/servers/databases/mariadb/install_mariadb.py', 0o700]] + + # Format first array element is command with the interpreter, the task is agnostic, the files in os directory. The commands are setted with 750 permission. + # First element is the file, next elements are the arguments + + #self.commands_to_execute=[['modules/pastafari/scripts/servers/databases/mysql/install_mariadb.py', '']]; + + #THe files to delete + + self.delete_files=[] + + self.delete_directories=['modules/pastafari2/scripts/servers/databases/mariadb'] + + #self.task=Task(conn) + + self.one_time=True + + self.version='1.0' + + self.arr_form=OrderedDict() + + self.arr_form['mysql_password']=coreforms.PasswordForm('mysql_password', '') + + self.arr_form['mysql_password'].required=True + + self.arr_form['mysql_password'].label='The MySQL password used by all servers' + + self.arr_form['repeat_mysql_password']=coreforms.PasswordForm('repeat_mysql_password', '') + + self.arr_form['repeat_mysql_password'].required=True + + self.arr_form['repeat_mysql_password'].label='Repeat MySQL password' + + #self.commands_to_execute=[['modules/pastafari/scripts/servers/databases/mariadb/install_mariadb.py', '--password=%s' % self.data['mysql_password']]] + + + def pre_task(self): + + self.commands_to_execute=[['modules/pastafari2/scripts/servers/databases/mariadb/install_mariadb.py', '--password=%s' % self.data['mysql_password']]] + + return True + + def form(self, t, yes_error=False, pass_values=False, values={}): + + #Here load the form for it task + + return '