Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ba6ba173
authored
Feb 07, 2024
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reconnect fix
parent
145e2a6d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
19 deletions
+32
-19
agent.py
+26
-17
linux/posixvirtio.py
+6
-2
No files found.
agent.py
View file @
ba6ba173
...
...
@@ -42,22 +42,27 @@ logger.setLevel(level)
class
SerialLineReceiver
(
SerialLineReceiverBase
):
def
__init__
(
self
):
super
(
SerialLineReceiver
,
self
)
.
__init__
()
self
.
tickId
=
LoopingCall
(
self
.
tick
)
reactor
.
addSystemEventTrigger
(
"before"
,
"shutdown"
,
self
.
shutdown
)
self
.
running
=
True
def
connectionMade
(
self
):
logger
.
debug
(
"connectionMade"
)
self
.
tickId
.
start
(
5
,
now
=
False
)
self
.
transport
.
dataBuffer
=
b
""
self
.
transport
.
_tempDataBuffer
=
[]
# will be added to dataBuffer in doWrite
self
.
transport
.
_tempDataLen
=
0
self
.
transport
.
write
(
'
\r\n
'
)
self
.
send_command
(
command
=
'agent_started'
,
args
=
{
'version'
:
Context
.
get_agent_version
(),
'system'
:
system
})
def
shutdown
():
self
.
connectionLost2
(
'shutdown'
)
d
=
defer
.
Deferred
()
reactor
.
callLater
(
0.3
,
d
.
callback
,
"1"
)
return
d
reactor
.
addSystemEventTrigger
(
"before"
,
"shutdown"
,
shutdown
)
if
self
.
running
:
self
.
send_command
(
command
=
'agent_started'
,
args
=
{
'version'
:
Context
.
get_agent_version
(),
'system'
:
system
})
def
connectionLost
(
self
,
reason
):
reactor
.
stop
()
logger
.
debug
(
"connectionLost"
)
self
.
tickId
.
stop
()
def
connectionLost2
(
self
,
reason
):
self
.
send_command
(
command
=
'agent_stopped'
,
...
...
@@ -70,10 +75,13 @@ class SerialLineReceiver(SerialLineReceiverBase):
except
Exception
:
logger
.
exception
(
"Twisted hide exception"
)
def
__init__
(
self
):
super
(
SerialLineReceiver
,
self
)
.
__init__
()
self
.
lc
=
LoopingCall
(
self
.
tick
)
self
.
lc
.
start
(
5
,
now
=
False
)
def
shutdown
(
self
):
self
.
running
=
False
logger
.
debug
(
"shutdown"
)
self
.
connectionLost2
(
'shutdown'
)
d
=
defer
.
Deferred
()
reactor
.
callLater
(
0.3
,
d
.
callback
,
"1"
)
return
d
def
send_status
(
self
):
import
psutil
...
...
@@ -113,6 +121,7 @@ class SerialLineReceiver(SerialLineReceiverBase):
self
.
_pretty_fun
(
func
),
", "
.
join
(
missing_kwargs
)))
def
_get_command
(
self
,
command
,
args
):
logger
.
debug
(
"_get_command
%
s
%
s"
%
(
command
,
args
))
if
not
isinstance
(
command
,
basestring
)
or
command
.
startswith
(
'_'
):
raise
AttributeError
(
u'Invalid command:
%
s'
%
command
)
try
:
...
...
@@ -142,6 +151,7 @@ class SerialLineReceiver(SerialLineReceiverBase):
return
"<
%
s>"
%
type
(
fun
)
.
__name__
def
handle_command
(
self
,
command
,
args
):
logger
.
debug
(
"handle_command
%
s
%
s"
%
(
command
,
args
))
func
=
self
.
_get_command
(
command
,
args
)
retval
=
func
(
**
args
)
self
.
send_response
(
...
...
@@ -151,7 +161,6 @@ class SerialLineReceiver(SerialLineReceiverBase):
def
handle_response
(
self
,
response
,
args
):
pass
def
main
():
# Get proper serial class and port name
(
serial
,
port
)
=
get_serial
()
...
...
linux/posixvirtio.py
View file @
ba6ba173
...
...
@@ -34,6 +34,7 @@ class SerialPort(abstract.FileDescriptor):
self
.
port
,
os
.
O_RDWR
|
os
.
O_NOCTTY
|
os
.
O_NONBLOCK
)
self
.
reactor
=
reactor
self
.
protocol
=
protocol
self
.
connected
=
1
self
.
protocol
.
makeConnection
(
self
)
self
.
startReading
()
...
...
@@ -60,9 +61,12 @@ class SerialPort(abstract.FileDescriptor):
serial data.
"""
abstract
.
FileDescriptor
.
connectionLost
(
self
,
reason
)
self
.
protocol
.
connectionLost
(
reason
)
os
.
close
(
self
.
_serial
)
sleep
(
2
)
logger
.
debug
(
"Reconecting after 5s"
)
sleep
(
5
)
self
.
_serial
=
os
.
open
(
self
.
port
,
os
.
O_RDWR
|
os
.
O_NOCTTY
|
os
.
O_NONBLOCK
)
self
.
connected
=
1
self
.
protocol
.
makeConnection
(
self
)
self
.
startReading
()
logger
.
info
(
"Reconnecting"
)
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