Commit aaf3bfea by Szeberényi Imre

Install fix

parent ecbb709b
NOTES - aka, mivel lehet szivni... NOTES - aka, mivel lehet szivni...
Agent = python3
__INSTALL__ __INSTALL__
* adott egy bootstrap script, ami minden szukseges elokeszuletet megcsinal, ami az agens mukodesehez kell: * cd /root
+ alap csomagokat telepit fel * mkvirtualenv agent
+ konyvtarakat hoz letre * workon agent
+ usereket hoz letre es allit be * git clone https://git.ik.bme.hu/CIRCLE3/agent.git
+ letolti az agent forrasat * cd agent
+ felpatcheli az rc-t * python agent.py
+ telepiti az agenst
__RC.D__ __RC.D__
* minden egyes circle_agent altal eszkozolt beallitas a /etc/rc.conf.d/-ben talalhato egy kulon file alatt * nem tamogatott
* 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 __SYSTEMD__
* az agent daemon-kent fut * 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__ __SMBFS__
* mindenhol case insensitive, kiveve a /etc/nsmb.conf-ban es a ~/.nsmbrc-ben, itt a userneveket szigoruan upper-case kell irni * 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__ ...@@ -26,7 +27,7 @@ __ROUTING__
* {ipv6_,}defaultrouter-eket kell beallitani * {ipv6_,}defaultrouter-eket kell beallitani
__USER__ __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 * a passwd update mindket felhasznalora hatassal van
__SERIAL__ __SERIAL__
......
...@@ -2,24 +2,38 @@ ...@@ -2,24 +2,38 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from os import environ, chdir from os import environ, chdir
import logging
import platform import platform
import subprocess import subprocess
import sys 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 system = platform.system() # noqa
logger.debug("system:%s", system)
if system == "Linux" or system == "FreeBSD": # noqa if system == "Linux" or system == "FreeBSD": # noqa
logger.debug("system:%s", system)
try: # noqa try: # noqa
chdir(sys.path[0]) # noqa chdir(sys.path[0]) # noqa
subprocess.call(('pip', 'install', '-r', 'requirements/linux.txt')) # 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 pass # hope it works # noqa
from twisted.internet import reactor, defer from twisted.internet import reactor, defer
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
import uptime import uptime
import logging
from inspect import getargs, isfunction from inspect import getargs, isfunction
from utils import SerialLineReceiverBase from utils import SerialLineReceiverBase
...@@ -43,15 +57,6 @@ except ImportError: ...@@ -43,15 +57,6 @@ except ImportError:
Context = get_context() 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): class SerialLineReceiver(SerialLineReceiverBase):
def __init__(self): def __init__(self):
......
...@@ -54,7 +54,7 @@ def get_serial(): ...@@ -54,7 +54,7 @@ def get_serial():
elif system == "Linux": elif system == "Linux":
port = "/dev/virtio-ports/agent" port = "/dev/virtio-ports/agent"
try: try:
print("Open!") logger.debug("Open!")
open(port, 'r').close() open(port, 'r').close()
except (OSError, IOError) as e: except (OSError, IOError) as e:
print(e) print(e)
......
...@@ -10,6 +10,7 @@ respawn limit 30 30 ...@@ -10,6 +10,7 @@ respawn limit 30 30
script script
cd /root/agent cd /root/agent
. /root/.virtualenvs/agent/bin/activate . /root/.virtualenvs/agent/bin/activate
. /root/.virtualenvs/agent/bin/postactivate
python agent.py python agent.py
end script end script
...@@ -4,7 +4,7 @@ Description=CIRCLE agent ...@@ -4,7 +4,7 @@ Description=CIRCLE agent
Before=network.target Before=network.target
[Service] [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 Restart=always
......
#!/bin/bash #!/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 ...@@ -2,6 +2,8 @@ from twisted.protocols.basic import LineReceiver
import json import json
import logging import logging
import platform import platform
from os import chmod
from shutil import copyfile
try: try:
# Python 2: "unicode" is built-in # Python 2: "unicode" is built-in
...@@ -24,7 +26,7 @@ class SerialLineReceiverBase(LineReceiver, object): ...@@ -24,7 +26,7 @@ class SerialLineReceiverBase(LineReceiver, object):
super(SerialLineReceiverBase, self).__init__(*args, **kwargs) super(SerialLineReceiverBase, self).__init__(*args, **kwargs)
def send_response(self, response, args): 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, self.transport.write(json.dumps({'response': response,
'args': args}) + '\r\n') 'args': args}) + '\r\n')
...@@ -67,3 +69,27 @@ class SerialLineReceiverBase(LineReceiver, object): ...@@ -67,3 +69,27 @@ class SerialLineReceiverBase(LineReceiver, object):
logger.debug('received reply: %s (%s)' % (response, args)) logger.debug('received reply: %s (%s)' % (response, args))
self.clearLineBuffer() self.clearLineBuffer()
self.handle_response(response, args) 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