Fixes in install

This commit is contained in:
absurdo 2024-03-10 00:35:29 +01:00
parent 1a20fdd944
commit 43f69c6c2d
6 changed files with 76 additions and 26 deletions

View file

@ -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

17
app.py
View file

@ -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)
"""

View file

@ -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:

View file

@ -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}')

View file

@ -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

View file

@ -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):