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
6af82bb2
authored
Feb 11, 2024
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
winservice fix
parent
c88ceaa3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
9 deletions
+29
-9
agent-winservice.py
+17
-6
watchdog-winservice.py
+12
-3
win_exe/agent-winservice.exe
+0
-0
win_exe/watchdog-winservice.exe
+0
-0
No files found.
agent-winservice.py
View file @
6af82bb2
...
@@ -27,11 +27,12 @@ logger.info("%s loaded", __file__)
...
@@ -27,11 +27,12 @@ logger.info("%s loaded", __file__)
class
AppServerSvc
(
win32serviceutil
.
ServiceFramework
):
class
AppServerSvc
(
win32serviceutil
.
ServiceFramework
):
_svc_name_
=
"circle-agent"
_svc_name_
=
"circle-agent"
_svc_display_name_
=
"CIRCLE Agent"
_svc_display_name_
=
"CIRCLE Agent"
_svc_desciption_
=
"CIRCLE cloud contextualization agent"
def
__init__
(
self
,
args
):
def
__init__
(
self
,
args
):
win32serviceutil
.
ServiceFramework
.
__init__
(
self
,
args
)
win32serviceutil
.
ServiceFramework
.
__init__
(
self
,
args
)
self
.
hWaitStop
=
win32event
.
CreateEvent
(
None
,
0
,
0
,
None
)
self
.
hWaitStop
=
win32event
.
CreateEvent
(
None
,
0
,
0
,
None
)
socket
.
setdefaulttimeout
(
6
0
)
socket
.
setdefaulttimeout
(
12
0
)
def
SvcStop
(
self
):
def
SvcStop
(
self
):
self
.
ReportServiceStatus
(
win32service
.
SERVICE_STOP_PENDING
)
self
.
ReportServiceStatus
(
win32service
.
SERVICE_STOP_PENDING
)
...
@@ -40,15 +41,25 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
...
@@ -40,15 +41,25 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
logger
.
info
(
"
%
s stopped"
,
__file__
)
logger
.
info
(
"
%
s stopped"
,
__file__
)
def
SvcDoRun
(
self
):
def
SvcDoRun
(
self
):
servicemanager
.
LogMsg
(
servicemanager
.
EVENTLOG_INFORMATION_TYPE
,
servicemanager
.
PYS_SERVICE_STARTED
,
(
self
.
_svc_name_
,
''
))
logger
.
info
(
"
%
s starting"
,
__file__
)
logger
.
info
(
"
%
s starting"
,
__file__
)
agent_main
()
cnt
=
3
while
cnt
>
0
:
try
:
servicemanager
.
LogMsg
(
servicemanager
.
EVENTLOG_INFORMATION_TYPE
,
servicemanager
.
PYS_SERVICE_STARTED
,
(
self
.
_svc_name_
,
''
))
break
except
Exception
as
e
:
logger
.
exception
(
"Servicemanager busy?"
,
e
)
cnt
-=
1
if
cnt
:
logger
.
info
(
"Starting agent_main"
)
agent_main
()
def
main
():
def
main
():
if
len
(
sys
.
argv
)
==
1
:
# never happen set 1 for debugging!!!!
logger
.
info
(
"Started:
%
s"
,
sys
.
argv
)
if
len
(
sys
.
argv
)
==
1
:
# service must be starting...
# service must be starting...
# for the sake of debugging etc, we use win32traceutil to see
# for the sake of debugging etc, we use win32traceutil to see
# any unhandled exceptions and print statements.
# any unhandled exceptions and print statements.
...
...
watchdog-winservice.py
View file @
6af82bb2
...
@@ -31,13 +31,21 @@ def watch():
...
@@ -31,13 +31,21 @@ def watch():
def
start_service
():
def
start_service
():
win32serviceutil
.
StartService
(
service_name
)
win32serviceutil
.
StartService
(
service_name
)
timo_base
=
10
timo
=
timo_base
while
True
:
while
True
:
if
not
check_service
(
service_name
):
if
not
check_service
(
service_name
):
logger
.
info
(
"Service
%
s is not running."
,
service_name
)
logger
.
info
(
"Service
%
s is not running."
,
service_name
)
start_service
()
try
:
start_service
()
timo
=
timo_base
logger
.
info
(
"Service
%
s started."
,
service_name
)
except
Exception
as
e
:
timo
*=
2
logger
.
exception
(
"Cant start service
%
s new timo:
%
s"
%
(
service_name
,
timo
))
if
stopped
:
if
stopped
:
return
return
sleep
(
10
)
sleep
(
timo
)
class
AppServerSvc
(
win32serviceutil
.
ServiceFramework
):
class
AppServerSvc
(
win32serviceutil
.
ServiceFramework
):
...
@@ -65,7 +73,8 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
...
@@ -65,7 +73,8 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
def
main
():
def
main
():
if
len
(
sys
.
argv
)
==
1
:
# never happen set 1 for debugging!!!!
logger
.
info
(
"Started:
%
s"
,
sys
.
argv
)
if
len
(
sys
.
argv
)
==
1
:
# service must be starting...
# service must be starting...
# for the sake of debugging etc, we use win32traceutil to see
# for the sake of debugging etc, we use win32traceutil to see
# any unhandled exceptions and print statements.
# any unhandled exceptions and print statements.
...
...
win_exe/agent-winservice.exe
View file @
6af82bb2
No preview for this file type
win_exe/watchdog-winservice.exe
View file @
6af82bb2
No preview for this file type
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