diff --git a/README.md b/README.md index 71efc1e..df87645 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ # Pastafari2, a simple panel for control servers. +## What is Pastafari2 + +Pastafari2 is a module for Paramecio2 Python Framework that is used in combination with rq for create a control panel for servers. You can update, install webservers how Apache, database servers, install applications... + +## Installation + +For installatio you need install Paramecio2 framework first. You can install diff --git a/app.py b/app.py index 56cc7d3..b4cc450 100644 --- a/app.py +++ b/app.py @@ -5,20 +5,3 @@ try: import ujson as json except: import json -""" -server=ServerDbTask() - -@pastafari_app.route('/test') -def test(): - - conn=WebModel.connection() - - cursor=conn.query('select * from serverdbtask') - - arr_row=[] - - for row in cursor: - arr_row.append(row) - - return json.dumps(arr_row) -""" diff --git a/libraries/task.py b/libraries/task.py index 8e7413f..393b5bc 100644 --- a/libraries/task.py +++ b/libraries/task.py @@ -587,17 +587,28 @@ class Task: if hasattr(self, 'post_task'): self.logtask.insert({'task_id': self.id, 'progress': 0, 'message': I18n.lang('pastafari', 'post_tasks', 'Post tasks executing...'), 'error': 0, 'status': 0, 'server': self.server}) - if self.post_task(): - self.logtask.insert({'task_id': self.id, 'progress': 100, 'message': I18n.lang('pastafari', 'post_tasks_executed', 'Post tasks executed successfully...'), 'error': 0, 'status': 0, 'server': self.server}) - else: - #self.logtask.set_conditions('where id=%s', [last_log_id]) + try: + + if self.post_task(): + self.logtask.insert({'task_id': self.id, 'progress': 100, 'message': I18n.lang('pastafari', 'post_tasks_executed', 'Post tasks executed successfully...'), 'error': 0, 'status': 0, 'server': self.server}) + else: + #self.logtask.set_conditions('where id=%s', [last_log_id]) + + #self.logtask.update({'progress': 100, 'error': 1, 'message': "Error executing post task", 'status': 1, 'server': self.server}) - #self.logtask.update({'progress': 100, 'error': 1, 'message': "Error executing post task", 'status': 1, 'server': self.server}) + self.logtask.insert({'task_id': self.id, 'progress': 100, 'message': I18n.lang('pastafari', 'error_post_tasks_executed', 'Error executing post task -> '+self.error_post_task), 'error': 1, 'status': 1, 'server': self.server}) + self.make_error_task() + return False + except: - self.logtask.insert({'task_id': self.id, 'progress': 100, 'message': I18n.lang('pastafari', 'error_post_tasks_executed', 'Error executing post task -> '+self.error_post_task), 'error': 1, 'status': 1, 'server': self.server}) + + #traceback.print_exception(exc_type, exc_value, tb) + #traceback.format_exc() + + self.logtask.insert({'task_id': self.id, 'progress': 100, 'message': I18n.lang('pastafari', 'error_post_tasks_executed', 'Error executing post task -> '+traceback.format_exc()), 'error': 1, 'status': 1, 'server': self.server}) self.make_error_task() - return False + return False if 'progress' in json_code: #if json_code['progress']!=100: diff --git a/scripts/system/install_pastafariutils.py b/scripts/system/install_pastafariutils.py new file mode 100644 index 0000000..13c6cdf --- /dev/null +++ b/scripts/system/install_pastafariutils.py @@ -0,0 +1,47 @@ +#!/usr/bin/python3 -u + +import sys, os +import subprocess +import argparse +import platform +import shutil +import pathlib +import distro +import pwd +import getpass +import re +import platform +import json + +#import pymysql.cursors +#pymysql.install_as_MySQLdb + +pyv=platform.python_version_tuple() + +if pyv[0]!='3': + print('Need python 3 for execute this script') + sys.exit(1) + +parser=argparse.ArgumentParser(prog='install_pastafariutils.py', description='Add pastafariutils for a system user') + +parser.add_argument('--user', help='The user used for install pastafariutils', required=True) + +args=parser.parse_args() + +user=args.user + +# https://git.cuchulu.com/paramecio/pastafariutils.git +# python3 -m venv /home/{}/pythonenv/ && source /home/{}/pythonenv/bin/activate && pip3 install git+https://git.cuchulu.com/paramecio/pastafariutils.git + +if subprocess.call("sudo su - {} -s /bin/bash -c 'cd /home/{} && python3 -m venv /home/{}/pythonenv/ && . /home/{}/pythonenv/bin/activate && pip3 install git+https://git.cuchulu.com/paramecio/pastafariutils.git && pip3 install distro'".format(user, user, user, user), shell=True) > 0: + print('Error, cannot install pastafariutils...') + exit(1) + +print("pastafariutils installed...") + +# #{'result': 1, 'message': {'username': 'hosting', 'uid': 1002, 'gid': 1002, 'home': '/srv/sites'}, 'error': 0, 'progress': 100, 'task_id': 483, 'server': '192.168.122.55'} +#json_code['message']=json.dumps(json_code['message']) + +print(json.dumps({'error': 0, 'status': 1, 'progress': 100, 'no_progress':0, 'message': '{"distro": "'+distro.id()+'"}', 'result': 1})) + +#print('{"error": 0, "status": 1, "progress": 100, "no_progress":0, "message": "{\\"distro\\": \\"'+distro.id()+'\\"}", "result": 1}') diff --git a/scripts/system/install_python.sh b/scripts/system/install_python.sh index 8ceaf65..aa94fbe 100644 --- a/scripts/system/install_python.sh +++ b/scripts/system/install_python.sh @@ -13,8 +13,8 @@ DISTRO=`( lsb_release -ds || cat /etc/*release || uname -om ) 2>/dev/null | head if [[ $DISTRO =~ ^Debian ]] || [[ $DISTRO =~ ^Ubuntu ]]; then apt-get update - apt-get install sudo - sudo apt-get -y install python3 python3-full python3-pip python3-venv libaugeas0 python3-distro + apt-get -y install sudo + sudo DEBIAN_FRONTEND="noninteractive" apt-get -y install python3 python3-full python3-pip python3-venv libaugeas0 python3-distro elif [[ $DISTRO =~ ^NAME=\"Arch ]]; then diff --git a/tasks/system/task.py b/tasks/system/task.py index 8a1bb20..d818365 100644 --- a/tasks/system/task.py +++ b/tasks/system/task.py @@ -19,6 +19,7 @@ class ServerTask(Task): self.files.append(['modules/pastafari2/scripts/system/install_composer.sh', 0o755]) #self.files.append(['modules/pastafari2/scripts/system/install_unixutils.sh', 0o755]) self.files.append(['modules/pastafari2/scripts/system/sudoers.d/spanel', 0o640]) + self.files.append(['modules/pastafari2/scripts/system/install_leviathanutils.py', 0o755]) self.files.append(['modules/pastafari2/scripts/system/install_pastafariutils.py', 0o755]) self.files.append([self.data['pub_key'], 0o600]) @@ -34,6 +35,7 @@ class ServerTask(Task): self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_pzoo_stats.py', '--user='+self.data['ssh_user']+' --pub_key='+self.data['pub_key']+' --group="'+self.data['group_name']+'" --path='+remote_path]) self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_pastafariutils.py', '--user='+self.data['ssh_user']]) + self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_leviathanutils.py', '--user='+self.data['ssh_user']]) def post_task(self):