Fixes in more quit monit dependencies
This commit is contained in:
parent
65111f67ae
commit
e4905c9769
4 changed files with 157 additions and 146 deletions
|
|
@ -224,7 +224,7 @@ def pastafari2_add_server_task():
|
|||
|
||||
except:
|
||||
pass
|
||||
|
||||
ssh_port='22'
|
||||
|
||||
|
||||
#make ping to server
|
||||
|
|
@ -233,6 +233,10 @@ def pastafari2_add_server_task():
|
|||
error=1
|
||||
error_form['#server_host_error']=I18n.lang('pastafari2', 'error_hostname', 'Error: you need enter a valid hostname')
|
||||
|
||||
if server_username=='':
|
||||
error=1
|
||||
error_form['#server_username_error']=I18n.lang('pastafari2', 'error_username', 'Error: you need enter a valid username for the server')
|
||||
|
||||
txt_error=''
|
||||
|
||||
try:
|
||||
|
|
@ -252,7 +256,9 @@ def pastafari2_add_server_task():
|
|||
arr_group=server_group.set_conditions('WHERE id=%s', [group_id]).select_a_row_where()
|
||||
group_name=arr_group['code_group']
|
||||
|
||||
data={'ssh_user': ssh_user, 'pub_key': public_key, 'url_stats': config.domain_url+url_for('monit_app.monit_get_data', api_key=config.monit_api_key), 'hostname': server_host, 'ip': ip, 'group_id': group_id, 'group_name': group_name}
|
||||
# 'url_stats': config.domain_url+url_for('monit_app.monit_get_data', api_key=config.monit_api_key)
|
||||
|
||||
data={'ssh_user': ssh_user, 'pub_key': public_key, 'hostname': server_host, 'ip': ip, 'group_id': group_id, 'group_name': group_name}
|
||||
|
||||
with SSHTask(server_host, db, remote_user=server_username, remote_password=server_password, private_key=private_key, remote_path=remote_path, task_id=task_id, data=data, port=ssh_port) as ssh_task:
|
||||
if not ssh_task.prepare_connection():
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import distro
|
|||
parser = argparse.ArgumentParser(description='A script for install leviathan user')
|
||||
|
||||
#parser.add_argument('--url', help='The url where notify updates', required=True)
|
||||
parser.add_argument('--url_stats', help='The url where pastafaristats notify the stats', required=True)
|
||||
#parser.add_argument('--url_stats', help='The url where pastafaristats notify the stats', required=True)
|
||||
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)
|
||||
|
|
@ -38,9 +38,9 @@ print('{"error": 0, "status": 0, "progress": 0, "no_progress":0, "message": "Ins
|
|||
|
||||
#check_url.match(args.url) and
|
||||
|
||||
if check_url.match(args.url_stats):
|
||||
#if check_url.match(args.url_stats):
|
||||
|
||||
try:
|
||||
try:
|
||||
u=pwd.getpwnam(args.user)
|
||||
|
||||
if call("sudo userdel -r %s" % args.user, shell=True) > 0:
|
||||
|
|
@ -49,12 +49,12 @@ if check_url.match(args.url_stats):
|
|||
else:
|
||||
print('Cleaning user with the same name')
|
||||
|
||||
except:
|
||||
except:
|
||||
pass
|
||||
|
||||
# Create users
|
||||
# Create users
|
||||
|
||||
if call("sudo useradd -m -s /bin/bash %s" % args.user, shell=True) > 0:
|
||||
if call("sudo useradd -m -s /bin/bash %s" % args.user, shell=True) > 0:
|
||||
|
||||
# Delete user with this name, you should not install it in a old server.
|
||||
|
||||
|
|
@ -67,70 +67,70 @@ if check_url.match(args.url_stats):
|
|||
print('Error, cannot add a new user')
|
||||
exit(1)
|
||||
|
||||
else:
|
||||
else:
|
||||
print('Added user')
|
||||
|
||||
if call("sudo mkdir -p /home/"+args.user+"/.ssh && sudo chown "+args.user+":"+args.user+" /home/"+args.user+"/.ssh && sudo chmod 700 /home/"+args.user+"/.ssh", shell=True) > 0:
|
||||
if call("sudo mkdir -p /home/"+args.user+"/.ssh && sudo chown "+args.user+":"+args.user+" /home/"+args.user+"/.ssh && sudo chmod 700 /home/"+args.user+"/.ssh", shell=True) > 0:
|
||||
print('Error, cannot add ssh directory')
|
||||
exit(1)
|
||||
else:
|
||||
else:
|
||||
print('Added ssh directory')
|
||||
|
||||
if call("sudo cp "+args.pub_key+" /home/"+args.user+"/.ssh/authorized_keys && sudo chown "+args.user+":"+args.user+" /home/"+args.user+"/.ssh/authorized_keys && sudo chmod 600 /home/"+args.user+"/.ssh/authorized_keys", shell=True) > 0:
|
||||
if call("sudo cp "+args.pub_key+" /home/"+args.user+"/.ssh/authorized_keys && sudo chown "+args.user+":"+args.user+" /home/"+args.user+"/.ssh/authorized_keys && sudo chmod 600 /home/"+args.user+"/.ssh/authorized_keys", shell=True) > 0:
|
||||
print('Error, cannot pub key to user')
|
||||
exit(1)
|
||||
else:
|
||||
else:
|
||||
print('Added pub key to user')
|
||||
|
||||
# Edit sudo file
|
||||
# Edit sudo file
|
||||
|
||||
with open('modules/pastafari2/scripts/system/sudoers.d/spanel') as f:
|
||||
with open('modules/pastafari2/scripts/system/sudoers.d/spanel') as f:
|
||||
sudoers=f.read()
|
||||
|
||||
with open('/etc/sudoers.d/spanel', 'w') as f:
|
||||
with open('/etc/sudoers.d/spanel', 'w') as f:
|
||||
sudoers=sudoers.replace("spanel", args.user)
|
||||
f.write(sudoers)
|
||||
|
||||
# Installing composer things for php alerts...
|
||||
# Installing composer things for php alerts...
|
||||
|
||||
|
||||
#mkdir $HOME/pzoo/scripts
|
||||
#mkdir $HOME/pzoo/scripts
|
||||
|
||||
#chown $USER:$USER $HOME/pzoo/scripts
|
||||
#chown $USER:$USER $HOME/pzoo/scripts
|
||||
|
||||
#su - $USER -s /bin/bash -c "composer --working-dir=$HOME/scripts require guzzlehttp/guzzle:~6.0"
|
||||
#su - $USER -s /bin/bash -c "composer --working-dir=$HOME/scripts require guzzlehttp/guzzle:~6.0"
|
||||
|
||||
args.path=os.path.basename(args.path)
|
||||
args.path=os.path.basename(args.path)
|
||||
|
||||
pt=Path('/home/'+args.user+'/'+args.path+'/tasks')
|
||||
pt=Path('/home/'+args.user+'/'+args.path+'/tasks')
|
||||
|
||||
pt.mkdir(mode=0o755, parents=True, exist_ok=True)
|
||||
pt.mkdir(mode=0o755, parents=True, exist_ok=True)
|
||||
|
||||
shutil.chown('/home/'+args.user+'/'+args.path, args.user, args.user)
|
||||
shutil.chown('/home/'+args.user+'/'+args.path, args.user, args.user)
|
||||
|
||||
shutil.chown('/home/'+args.user+'/'+args.path+'/tasks', args.user, args.user)
|
||||
shutil.chown('/home/'+args.user+'/'+args.path+'/tasks', args.user, args.user)
|
||||
|
||||
# Create scripts pzoo
|
||||
"""
|
||||
if call("sudo /opt/pythonenv/bin/pip3 install --upgrade git+https://bitbucket.org/paramecio/pastafaristats", shell=True)>0:
|
||||
# Create scripts pzoo
|
||||
"""
|
||||
if call("sudo /opt/pythonenv/bin/pip3 install --upgrade git+https://bitbucket.org/paramecio/pastafaristats", shell=True)>0:
|
||||
print('Error, cannot install pastafari stats')
|
||||
exit(1)
|
||||
else:
|
||||
else:
|
||||
print('Added pastafari stats')
|
||||
|
||||
# Add configuration to pastafari stats
|
||||
# Add configuration to pastafari stats
|
||||
|
||||
if not os.path.isdir('/etc/pastafari'):
|
||||
if not os.path.isdir('/etc/pastafari'):
|
||||
# Create pastafari dir
|
||||
p=Path('/etc/pastafari')
|
||||
p.mkdir(mode=0o755, parents=False, exist_ok=True)
|
||||
|
||||
with open('/etc/pastafari/stats.cfg', 'w') as f:
|
||||
with open('/etc/pastafari/stats.cfg', 'w') as f:
|
||||
|
||||
f.write("[DEFAULT]\n\nurl_server="+args.url_stats+"\ngroup="+args.group)
|
||||
|
||||
|
||||
with open('/etc/systemd/system/pastafaristats.service', 'w') as f:
|
||||
with open('/etc/systemd/system/pastafaristats.service', 'w') as f:
|
||||
|
||||
#f.write(systemd_unit)
|
||||
f.write('# Save it in /etc/systemd/system/pastafaristats.service\n')
|
||||
|
|
@ -151,29 +151,31 @@ if check_url.match(args.url_stats):
|
|||
f.write('WantedBy=multi-user.target\n')
|
||||
|
||||
|
||||
if call("sudo systemctl enable pastafaristats.service && sudo systemctl start pastafaristats.service", shell=True)>0:
|
||||
if call("sudo systemctl enable pastafaristats.service && sudo systemctl start pastafaristats.service", shell=True)>0:
|
||||
print('Error, cannot start pastafari stats')
|
||||
exit(1)
|
||||
else:
|
||||
else:
|
||||
print('Pastafari stats ready')
|
||||
|
||||
print('{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Tools installed..."}')
|
||||
"""
|
||||
print('{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Tools installed..."}')
|
||||
"""
|
||||
|
||||
sleep(1)
|
||||
sleep(1)
|
||||
|
||||
linux_distro=distro.id()
|
||||
linux_distro=distro.id()
|
||||
|
||||
# sudo su - %s -s /bin/bash -c 'mkdir -p %s'
|
||||
# sudo su - %s -s /bin/bash -c 'mkdir -p %s'
|
||||
|
||||
if linux_distro=='arch':
|
||||
if linux_distro=='arch':
|
||||
print('Add utilities for archlinux distro...')
|
||||
if call("sudo su - %s -s /bin/bash -c 'sudo pacman -S --noconfirm --needed git base-devel && git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si --noconfirm --needed'" % args.user, shell=True) > 0:
|
||||
print('Error, cannot add utilities for archlinux')
|
||||
exit(1)
|
||||
|
||||
"""
|
||||
else:
|
||||
|
||||
print('Error installing the module, not valid url')
|
||||
|
||||
exit(1)
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -27,7 +27,10 @@ class ServerTask(Task):
|
|||
self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_php.py', ''])
|
||||
self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_unixutils.sh', ''])
|
||||
self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_psutil.sh', ''])
|
||||
self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_pzoo_stats.py', '--user='+self.data['ssh_user']+' --pub_key='+self.data['pub_key']+' --url_stats='+self.data['url_stats']+' --group="'+self.data['group_name']+'" --path='+remote_path])
|
||||
|
||||
#' --url_stats='+self.data['url_stats']+
|
||||
|
||||
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])
|
||||
|
||||
def post_task(self):
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
<form method="post" name="add_server" id="add_server_form">
|
||||
<p>Please fill the form for add the new server to the system.</p>
|
||||
<p><label>${lang('pastafari2', 'server_host', 'Server host')}* <span class="pastafari2_error error" id="server_host_error"></span></label> <input type="text" name="server_host" value=""></p>
|
||||
<p><label>${lang('pastafari2', 'server_group', 'Server group')} <span class="pastafari2_error error" id="group_id_error"></span></label> ${group_form.form()|n}</p>
|
||||
<p><label>${lang('pastafari2', 'server_username', 'Server username')} <span class="pastafari2_error error" id="server_username_error"></span></label> <input type="text" name="server_username" value=""></p>
|
||||
<p><label>${lang('pastafari2', 'server_group', 'Server group')}* <span class="pastafari2_error error" id="group_id_error"></span></label> ${group_form.form()|n}</p>
|
||||
<p><label>${lang('pastafari2', 'server_username', 'Server username')}* <span class="pastafari2_error error" id="server_username_error"></span></label> <input type="text" name="server_username" value=""></p>
|
||||
<p><label>${lang('pastafari2', 'server_password', 'Server password.')} <span class="pastafari2_error error" id="server_password_error"></span></label> <input type="password" name="server_password" value=""></p>
|
||||
<p><label>${lang('pastafari2', 'repeat_server_password', 'Repeat server password')} <span class="pastafari2_error error" id="repeat_server_password_error"></span></label> <input type="password" name="repeat_server_password" value=""></p>
|
||||
<p><label>${lang('pastafari2', 'ssh_port', 'SSH port')}* <span class="pastafari2_error error" id="ssh_port_error"></span></label> <input type="number" name="ssh_port" value="22"></p>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue