Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
84806585
Commit
84806585
authored
Feb 25, 2019
by
Дмитрий Никулин
Committed by
Никита Ефремов
Apr 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
System services: partial systemd support
parent
156f864c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
65 deletions
+25
-65
fmod_system_services.py
plugins/functions/fmod_system_services.py
+25
-65
No files found.
plugins/functions/fmod_system_services.py
View file @
84806585
...
@@ -5,6 +5,7 @@ import os
...
@@ -5,6 +5,7 @@ import os
import
stat
import
stat
import
re
import
re
import
pyinotify
import
pyinotify
from
dbus
import
SystemBus
,
Interface
as
DBusInterface
from
settingsd
import
config
from
settingsd
import
config
from
settingsd
import
service
from
settingsd
import
service
...
@@ -35,6 +36,10 @@ class SystemService(service.FunctionObject) :
...
@@ -35,6 +36,10 @@ class SystemService(service.FunctionObject) :
service
.
FunctionObject
.
__init__
(
self
,
object_path
,
service_object
)
service
.
FunctionObject
.
__init__
(
self
,
object_path
,
service_object
)
self
.
__system_service_name
=
system_service_name
self
.
__system_service_name
=
system_service_name
self
.
_bus
=
SystemBus
()
self
.
_systemd_manager
=
DBusInterface
(
self
.
_bus
.
get_object
(
'org.freedesktop.systemd1'
,
'/org/freedesktop/systemd1'
),
'org.freedesktop.systemd1.Manager'
)
### DBus methods ###
### DBus methods ###
...
@@ -53,78 +58,33 @@ class SystemService(service.FunctionObject) :
...
@@ -53,78 +58,33 @@ class SystemService(service.FunctionObject) :
def
off
(
self
,
levels
=
None
)
:
def
off
(
self
,
levels
=
None
)
:
return
self
.
setLevels
(
levels
,
False
)
return
self
.
setLevels
(
levels
,
False
)
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
levelsMap
(
self
)
:
proc_args_list
=
[
config
.
value
(
SERVICE_NAME
,
"chkconfig_bin"
),
"--list"
,
self
.
__system_service_name
]
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
process
.
execProcess
(
proc_args_list
)
service_record_list
=
re
.
split
(
r"\s+"
,
proc_stdout
.
split
(
"
\n
"
)[
0
])
levels_list
=
[
"0"
]
*
(
len
(
service_record_list
)
-
1
)
for
count
in
xrange
(
1
,
len
(
service_record_list
))
:
(
level
,
state
)
=
service_record_list
[
count
]
.
split
(
":"
)
levels_list
[
int
(
level
)]
=
(
"1"
if
state
==
"on"
else
"0"
)
return
""
.
join
(
levels_list
)
###
###
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"s"
)
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
""
)
def
shortDescription
(
self
)
:
return
""
# TODO: /usr/lib/python2.6/site-packages/scservices/core/servicesinfo.py in RHEL
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
description
(
self
)
:
return
""
# TODO: /usr/lib/python2.6/site-packages/scservices/core/servicesinfo.py in RHEL
###
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
start
(
self
)
:
def
start
(
self
)
:
logger
.
verbose
(
"{mod}: Request to start service
\"
%
s
\"
"
%
(
self
.
__system_service_name
))
logger
.
verbose
(
"{mod}: Request to start service
\"
%
s
\"
"
%
(
self
.
__system_service_name
))
proc_args_list
=
[
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
),
"start"
]
self
.
_systemd_manager
.
StartUnit
(
self
.
__system_service_name
+
'.service'
,
'replace'
)
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"
i
"
)
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
""
)
def
stop
(
self
)
:
def
stop
(
self
)
:
logger
.
verbose
(
"{mod}: Request to stop service
\"
%
s
\"
"
%
(
self
.
__system_service_name
))
logger
.
verbose
(
"{mod}: Request to stop service
\"
%
s
\"
"
%
(
self
.
__system_service_name
))
proc_args_list
=
[
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
),
"stop"
]
self
.
_systemd_manager
.
StopUnit
(
self
.
__system_service_name
+
'.service'
,
'replace'
)
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"b"
)
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
isActive
(
self
)
:
def
status
(
self
)
:
unit
=
DBusInterface
(
proc_args_list
=
[
self
.
_bus
.
get_object
(
config
.
value
(
SERVICE_NAME
,
"serv_mgr_command"
),
self
.
__system_service_name
,
"status"
'org.freedesktop.systemd1'
,
]
str
(
self
.
_systemd_manager
.
LoadUnit
(
self
.
__system_service_name
+
'.service'
))
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
),
'org.freedesktop.systemd1.Unit'
)
### Private ###
active_state
=
unit
.
Get
(
'org.freedesktop.systemd1.Unit'
,
def
setLevels
(
self
,
levels
,
enabled_flag
)
:
'ActiveState'
,
levels
=
self
.
validLevels
(
levels
)
dbus_interface
=
'org.freedesktop.DBus.Properties'
)
logger
.
verbose
(
"Request to
%
s service
\"
%
s
\"
on runlevels
\"
%
s
\"
"
%
(
(
"enable"
if
enabled_flag
else
"disable"
),
return
active_state
==
'active'
or
active_state
==
'reloading'
self
.
__system_service_name
,
(
levels
if
levels
!=
None
else
"default"
)
))
proc_args_list
=
(
[
config
.
value
(
SERVICE_NAME
,
"chkconfig_bin"
)]
+
(
[
"--level"
,
str
(
levels
)]
if
levels
!=
None
else
[]
),
self
.
__system_service_name
,
(
[
"on"
]
if
enabled_flag
else
[
"off"
]
)
)
return
tools
.
process
.
execProcess
(
proc_args_list
,
fatal_flag
=
False
)[
2
]
###
def
validLevels
(
self
,
levels
)
:
if
type
(
levels
)
.
__name__
in
(
"str"
,
"String"
)
:
if
len
(
levels
)
==
0
:
levels
=
None
for
level
in
levels
:
if
not
level
in
"0123456"
:
raise
validators
.
ValidatorError
(
"Incorrect item
\"
%
s
\"
in argument
\"
%
s
\"
"
%
(
level
,
levels
))
elif
type
(
levels
)
.
__name__
==
"NoneType"
:
pass
else
:
raise
validators
.
ValidatorError
(
"Incorrect type
\"
%
s
\"
of argument"
%
(
type
(
levels
)
.
__name__
))
return
levels
class
SystemServices
(
service
.
FunctionObject
)
:
class
SystemServices
(
service
.
FunctionObject
)
:
...
...
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