Commit aaf3bfea by Szeberényi Imre

Install fix

parent ecbb709b
NOTES - aka, mivel lehet szivni...
Agent = python3
__INSTALL__
* adott egy bootstrap script, ami minden szukseges elokeszuletet megcsinal, ami az agens mukodesehez kell:
+ alap csomagokat telepit fel
+ konyvtarakat hoz letre
+ usereket hoz letre es allit be
+ letolti az agent forrasat
+ felpatcheli az rc-t
+ telepiti az agenst
* cd /root
* mkvirtualenv agent
* workon agent
* git clone https://git.ik.bme.hu/CIRCLE3/agent.git
* cd agent
* python agent.py
__RC.D__
* minden egyes circle_agent altal eszkozolt beallitas a /etc/rc.conf.d/-ben talalhato egy kulon file alatt
* a FreeBSD-s rc.subr az agent telepitesekor modositasra kerul, mivel alapbol a partial config file-ok kezelese agyhalal es nem logikus
* az interface beallitasok a /etc/rc.conf.d/ifconfig_IFNAME alatt talalhatok
* az agent daemon-kent fut
* nem tamogatott
__SYSTEMD__
* bemasolja az agent.service-t /etc/systemd-be
* bemasolja a vm_renewal-t a /usr/bin/-be es engedélyezi, de nem indítja el
__SMBFS__
* mindenhol case insensitive, kiveve a /etc/nsmb.conf-ban es a ~/.nsmbrc-ben, itt a userneveket szigoruan upper-case kell irni
......@@ -26,7 +27,7 @@ __ROUTING__
* {ipv6_,}defaultrouter-eket kell beallitani
__USER__
* a cloud es a root felhasznalo ugyan azt a jelszot birtokolja minden idoben
* a cloud es a root felhasznalo ugyanazt a jelszot birtokolja minden idoben
* a passwd update mindket felhasznalora hatassal van
__SERIAL__
......
......@@ -2,24 +2,38 @@
# -*- coding: utf-8 -*-
from os import environ, chdir
import logging
import platform
import subprocess
import sys
from utils import copy_file
logging.basicConfig(
format="[%(asctime)s] %(levelname)s [agent %(process)d/%(thread)d] %(module)s.%(funcName)s:%(lineno)d] %(message)s",
datefmt="%d/%b/%Y %H:%M:%S",
)
logger = logging.getLogger()
level = environ.get('LOGLEVEL', 'INFO')
logger.setLevel(level)
system = platform.system() # noqa
logger.debug("system:%s", system)
if system == "Linux" or system == "FreeBSD": # noqa
logger.debug("system:%s", system)
try: # noqa
chdir(sys.path[0]) # noqa
subprocess.call(('pip', 'install', '-r', 'requirements/linux.txt')) # noqa
except Exception: # noqa
copy_file("misc/vm_renewal", "/usr/bin/vm_renewal", mode=0o755)
if copy_file("misc/agent.service", "/etc/systemd/system/agent.service"):
subprocess.call(('systemctl', 'enable', 'agent'))
except Exception as e: # noqa
logger.exception("Unhandled exeption: %s", e)
pass # hope it works # noqa
from twisted.internet import reactor, defer
from twisted.internet.task import LoopingCall
import uptime
import logging
from inspect import getargs, isfunction
from utils import SerialLineReceiverBase
......@@ -43,15 +57,6 @@ except ImportError:
Context = get_context()
logging.basicConfig(
format="[%(asctime)s] %(levelname)s [agent %(process)d/%(thread)d] %(module)s.%(funcName)s:%(lineno)d] %(message)s",
datefmt="%d/%b/%Y %H:%M:%S",
)
logger = logging.getLogger()
level = environ.get('LOGLEVEL', 'DEBUG')
logger.setLevel(level)
class SerialLineReceiver(SerialLineReceiverBase):
def __init__(self):
......
......@@ -54,7 +54,7 @@ def get_serial():
elif system == "Linux":
port = "/dev/virtio-ports/agent"
try:
print("Open!")
logger.debug("Open!")
open(port, 'r').close()
except (OSError, IOError) as e:
print(e)
......
......@@ -10,6 +10,7 @@ respawn limit 30 30
script
cd /root/agent
. /root/.virtualenvs/agent/bin/activate
. /root/.virtualenvs/agent/bin/postactivate
python agent.py
end script
......@@ -4,7 +4,7 @@ Description=CIRCLE agent
Before=network.target
[Service]
ExecStart=/bin/bash -c "cd /root/agent; . /root/.virtualenvs/agent/bin/activate; python agent.py"
ExecStart=/bin/bash -c "cd /root/agent; . /root/.virtualenvs/agent/bin/activate; . /root/.virtualenvs/agent/bin/postactivate; python agent.py"
Restart=always
......
#!/bin/bash
sudo bash -c "source /root/.virtualenvs/agent/bin/activate; source /root/.virtualenvs/agent/bin/postactivate 2>/dev/null; cd /root/agent; ./vm_renewal"
sudo bash -c "source /root/.virtualenvs/agent/bin/activate; source /root/.virtualenvs/agent/bin/postactivate; /root/agent/vm_renewal"
......@@ -2,6 +2,8 @@ from twisted.protocols.basic import LineReceiver
import json
import logging
import platform
from os import chmod
from shutil import copyfile
try:
# Python 2: "unicode" is built-in
......@@ -24,7 +26,7 @@ class SerialLineReceiverBase(LineReceiver, object):
super(SerialLineReceiverBase, self).__init__(*args, **kwargs)
def send_response(self, response, args):
# logger.debug("send_response %s %s" % (response, args))
logger.debug("send_response %s %s" % (response, args))
self.transport.write(json.dumps({'response': response,
'args': args}) + '\r\n')
......@@ -67,3 +69,27 @@ class SerialLineReceiverBase(LineReceiver, object):
logger.debug('received reply: %s (%s)' % (response, args))
self.clearLineBuffer()
self.handle_response(response, args)
def copy_file(src, dst, overw=False, mode=None):
exists = False
copyed = False
try:
open(dst, 'r').close()
exists = True
except FileNotFoundError:
pass
try:
if not exists or overw:
copyfile(src, dst)
copyed = True
logger.debug('copy_file:(%s, %s, %s, %s)' % (src, dst, overw, mode))
if mode != None:
chmod(dst, mode)
logger.debug('chmod:(%s, %s)' % (dst, mode))
except Exception as e:
logger.exception('Unhandled %s during copy_file:(%s, %s, %s, %s)' % (e, src, dst, overw, mode))
return copyed
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment