Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
aaf3bfea
authored
Dec 01, 2024
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Install fix
parent
ecbb709b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
28 deletions
+61
-28
README.md
+14
-13
agent.py
+16
-11
context.py
+1
-1
misc/agent.conf
+1
-0
misc/agent.service
+1
-1
misc/vm_renewal
+1
-1
utils.py
+27
-1
No files found.
NOTES
→
README.md
View file @
aaf3bfea
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__
...
...
agent.py
View file @
aaf3bfea
...
...
@@ -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
=
0
o755
)
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
):
...
...
context.py
View file @
aaf3bfea
...
...
@@ -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
)
...
...
misc/agent.conf
View file @
aaf3bfea
...
...
@@ -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
misc/agent.service
View file @
aaf3bfea
...
...
@@ -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
...
...
misc/vm_renewal
View file @
aaf3bfea
#!/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"
utils.py
View file @
aaf3bfea
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment