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
60255e9a
Commit
60255e9a
authored
Nov 12, 2010
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring all function modules for using tools
parent
b2ad9c4a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
108 deletions
+30
-108
fmod_common_info.py
plugins/functions/fmod_common_info.py
+5
-21
fmod_machine.py
plugins/functions/fmod_machine.py
+10
-27
fmod_ntp_config.py
plugins/functions/fmod_ntp_config.py
+3
-20
fmod_system_services.py
plugins/functions/fmod_system_services.py
+12
-40
No files found.
plugins/functions/fmod_common_info.py
View file @
60255e9a
...
@@ -7,6 +7,7 @@ from settingsd import config
...
@@ -7,6 +7,7 @@ from settingsd import config
from
settingsd
import
service
from
settingsd
import
service
from
settingsd
import
shared
from
settingsd
import
shared
from
settingsd
import
logger
from
settingsd
import
logger
from
settingsd
import
tools
##### Private constants #####
##### Private constants #####
...
@@ -31,11 +32,6 @@ UNAME_OPTION_HARDWARE_PLATFORM = "--hardware-platform"
...
@@ -31,11 +32,6 @@ UNAME_OPTION_HARDWARE_PLATFORM = "--hardware-platform"
UNAME_OPTION_OPERATING_SYSTEM
=
"--operating-system"
UNAME_OPTION_OPERATING_SYSTEM
=
"--operating-system"
##### Exceptions #####
class
SubprocessFailure
(
Exception
)
:
pass
##### Private classes #####
##### Private classes #####
class
CommonInfo
(
service
.
FunctionObject
)
:
class
CommonInfo
(
service
.
FunctionObject
)
:
...
@@ -100,36 +96,24 @@ class CommonInfo(service.FunctionObject) :
...
@@ -100,36 +96,24 @@ class CommonInfo(service.FunctionObject) :
def
lsbOption
(
self
,
option
)
:
def
lsbOption
(
self
,
option
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"lsb_release_prog_path"
),
option
)
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"lsb_release_prog_path"
),
option
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
self
.
execProcess
(
proc_args
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
if
proc_returncode
!=
0
:
raise
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
":"
.
join
(
proc_stdout
.
split
(
":"
)[
1
:])
.
strip
()
return
":"
.
join
(
proc_stdout
.
split
(
":"
)[
1
:])
.
strip
()
def
unameOption
(
self
,
option
)
:
def
unameOption
(
self
,
option
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"uname_prog_path"
),
option
)
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"uname_prog_path"
),
option
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
self
.
execProcess
(
proc_args
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
if
proc_returncode
!=
0
:
raise
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
proc_stdout
.
strip
()
return
proc_stdout
.
strip
()
###
def
execProcess
(
self
,
proc_args
)
:
logger
.
debug
(
"{mod}: Executing child process
\"
%
s
\"
"
%
(
proc_args
))
proc
=
subprocess
.
Popen
(
proc_args
,
shell
=
True
,
bufsize
=
1024
,
close_fds
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
{
"LC_ALL"
:
"C"
})
(
proc_stdout
,
proc_stderr
)
=
proc
.
communicate
()
logger
.
debug
(
"{mod}: Child process
\"
%
s
\"
finished, return_code=
%
d"
%
(
proc_args
,
proc
.
returncode
))
return
(
proc_stdout
,
proc_stderr
,
proc
.
returncode
)
##### Public classes #####
##### Public classes #####
class
Service
(
service
.
Service
)
:
class
Service
(
service
.
Service
)
:
...
...
plugins/functions/fmod_machine.py
View file @
60255e9a
...
@@ -7,6 +7,7 @@ from settingsd import config
...
@@ -7,6 +7,7 @@ from settingsd import config
from
settingsd
import
service
from
settingsd
import
service
from
settingsd
import
shared
from
settingsd
import
shared
from
settingsd
import
logger
from
settingsd
import
logger
from
settingsd
import
tools
from
settingsd
import
validators
from
settingsd
import
validators
...
@@ -22,11 +23,6 @@ SHUTDOWN_OPTION_HALT = "-h"
...
@@ -22,11 +23,6 @@ SHUTDOWN_OPTION_HALT = "-h"
SHUTDOWN_OPTION_REBOOT
=
"-r"
SHUTDOWN_OPTION_REBOOT
=
"-r"
##### Exceptions #####
class
SubprocessFailure
(
Exception
)
:
pass
##### Private classes #####
##### Private classes #####
class
Machine
(
service
.
FunctionObject
)
:
class
Machine
(
service
.
FunctionObject
)
:
...
@@ -35,36 +31,36 @@ class Machine(service.FunctionObject) :
...
@@ -35,36 +31,36 @@ class Machine(service.FunctionObject) :
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
shutdown
(
self
)
:
def
shutdown
(
self
)
:
proc_args
=
"
%
s
%
s now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_prog_path"
),
SHUTDOWN_OPTION_HALT
)
proc_args
=
"
%
s
%
s now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_prog_path"
),
SHUTDOWN_OPTION_HALT
)
return
self
.
execProcess
(
proc_args
)[
2
]
return
tools
.
execProcess
(
proc_args
)[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
reboot
(
self
)
:
def
reboot
(
self
)
:
proc_args
=
"
%
s
%
s now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_prog_path"
),
SHUTDOWN_OPTION_REBOOT
)
proc_args
=
"
%
s
%
s now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_prog_path"
),
SHUTDOWN_OPTION_REBOOT
)
return
self
.
execProcess
(
proc_args
)[
2
]
return
tools
.
execProcess
(
proc_args
)[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
suspend
(
self
)
:
def
suspend
(
self
)
:
return
self
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_suspend_prog_path"
))[
2
]
return
tools
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_suspend_prog_path"
))[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
hibernate
(
self
)
:
def
hibernate
(
self
)
:
return
self
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_hibernate_prog_path"
))[
2
]
return
tools
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_hibernate_prog_path"
))[
2
]
###
###
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
in_signature
=
"i"
,
out_signature
=
"i"
)
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
in_signature
=
"i"
,
out_signature
=
"i"
)
def
switchTo
(
self
,
level
)
:
def
switchTo
(
self
,
level
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"telinit_prog_path"
),
validators
.
validRange
(
str
(
level
),
RUNLEVELS
))
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"telinit_prog_path"
),
validators
.
validRange
(
str
(
level
),
RUNLEVELS
))
return
self
.
execProcess
(
proc_args
)[
2
]
return
tools
.
execProcess
(
proc_args
)[
2
]
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
currentLevel
(
self
)
:
def
currentLevel
(
self
)
:
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_prog_path"
)
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_prog_path"
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
self
.
execProcess
(
proc_args
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
level_pairs_list
=
proc_stdout
.
strip
()
.
split
(
" "
)
level_pairs_list
=
proc_stdout
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
:
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
:
raise
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
int
(
level_pairs_list
[
1
])
return
int
(
level_pairs_list
[
1
])
...
@@ -72,29 +68,16 @@ class Machine(service.FunctionObject) :
...
@@ -72,29 +68,16 @@ class Machine(service.FunctionObject) :
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
previousLevel
(
self
)
:
def
previousLevel
(
self
)
:
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_prog_path"
)
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_prog_path"
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
self
.
execProcess
(
proc_args
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
level_pairs_list
=
proc_stdout
.
strip
()
.
split
(
" "
)
level_pairs_list
=
proc_stdout
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
+
"N"
:
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
+
"N"
:
raise
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
(
int
(
level_pairs_list
[
0
])
if
level_pairs_list
[
0
]
in
RUNLEVELS
else
-
1
)
return
(
int
(
level_pairs_list
[
0
])
if
level_pairs_list
[
0
]
in
RUNLEVELS
else
-
1
)
### Private ###
def
execProcess
(
self
,
proc_args
)
:
logger
.
debug
(
"{mod}: Executing child process
\"
%
s
\"
"
%
(
proc_args
))
proc
=
subprocess
.
Popen
(
proc_args
,
shell
=
True
,
bufsize
=
1024
,
close_fds
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
{
"LC_ALL"
:
"C"
})
(
proc_stdout
,
proc_stderr
)
=
proc
.
communicate
()
logger
.
debug
(
"{mod}: Child process
\"
%
s
\"
finished, return_code=
%
d"
%
(
proc_args
,
proc
.
returncode
))
return
(
proc_stdout
,
proc_stderr
,
proc
.
returncode
)
##### Public classes #####
##### Public classes #####
class
Service
(
service
.
Service
)
:
class
Service
(
service
.
Service
)
:
...
...
plugins/functions/fmod_ntp_config.py
View file @
60255e9a
...
@@ -8,6 +8,7 @@ from settingsd import config
...
@@ -8,6 +8,7 @@ from settingsd import config
from
settingsd
import
service
from
settingsd
import
service
from
settingsd
import
shared
from
settingsd
import
shared
from
settingsd
import
logger
from
settingsd
import
logger
from
settingsd
import
tools
##### Private constants #####
##### Private constants #####
...
@@ -16,11 +17,6 @@ SERVICE_NAME = "ntp_config"
...
@@ -16,11 +17,6 @@ SERVICE_NAME = "ntp_config"
NTP_METHODS_NAMESPACE
=
"time.ntp"
NTP_METHODS_NAMESPACE
=
"time.ntp"
##### Exceptions #####
class
SubprocessFailure
(
Exception
)
:
pass
##### Private classes #####
##### Private classes #####
class
NtpConfig
(
service
.
FunctionObject
)
:
class
NtpConfig
(
service
.
FunctionObject
)
:
...
@@ -64,26 +60,13 @@ class NtpConfig(service.FunctionObject) :
...
@@ -64,26 +60,13 @@ class NtpConfig(service.FunctionObject) :
@service.functionMethod
(
NTP_METHODS_NAMESPACE
)
@service.functionMethod
(
NTP_METHODS_NAMESPACE
)
def
request
(
self
)
:
def
request
(
self
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"ntpdate_prog_path"
),
" "
.
join
(
self
.
servers
()))
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"ntpdate_prog_path"
),
" "
.
join
(
self
.
servers
()))
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
self
.
execProcess
(
proc_args
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
if
proc_returncode
!=
0
:
raise
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
### Private ###
def
execProcess
(
self
,
proc_args
)
:
logger
.
debug
(
"{mod}: Executing child process
\"
%
s
\"
"
%
(
proc_args
))
proc
=
subprocess
.
Popen
(
proc_args
,
shell
=
True
,
bufsize
=
1024
,
close_fds
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
{
"LC_ALL"
:
"C"
})
(
proc_stdout
,
proc_stderr
)
=
proc
.
communicate
()
logger
.
debug
(
"{mod}: Child process
\"
%
s
\"
finished, return_code=
%
d"
%
(
proc_args
,
proc
.
returncode
))
return
(
proc_stdout
,
proc_stderr
,
proc
.
returncode
)
##### Public classes #####
##### Public classes #####
class
Service
(
service
.
Service
)
:
class
Service
(
service
.
Service
)
:
...
...
plugins/functions/fmod_system_services.py
View file @
60255e9a
...
@@ -10,6 +10,8 @@ from settingsd import service
...
@@ -10,6 +10,8 @@ from settingsd import service
from
settingsd
import
shared
from
settingsd
import
shared
from
settingsd
import
dbus_tools
from
settingsd
import
dbus_tools
from
settingsd
import
logger
from
settingsd
import
logger
from
settingsd
import
tools
from
settingsd
import
validators
##### Private constants #####
##### Private constants #####
...
@@ -20,14 +22,6 @@ SYSTEM_SERVICE_METHODS_NAMESPACE = "systemService"
...
@@ -20,14 +22,6 @@ SYSTEM_SERVICE_METHODS_NAMESPACE = "systemService"
RUNLEVELS
=
"0123456"
RUNLEVELS
=
"0123456"
##### Exceptions #####
class
SubprocessFailure
(
Exception
)
:
pass
class
IncorrectArgument
(
Exception
)
:
pass
##### Private classes #####
##### Private classes #####
class
SystemService
(
service
.
FunctionObject
)
:
class
SystemService
(
service
.
FunctionObject
)
:
def
__init__
(
self
,
system_service_name
,
object_path
,
service_object
=
None
)
:
def
__init__
(
self
,
system_service_name
,
object_path
,
service_object
=
None
)
:
...
@@ -49,10 +43,10 @@ class SystemService(service.FunctionObject) :
...
@@ -49,10 +43,10 @@ class SystemService(service.FunctionObject) :
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"s"
)
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
levelsMap
(
self
)
:
def
levelsMap
(
self
)
:
proc_args
=
"
%
s --list
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_prog_path"
),
self
.
systemServiceName
())
proc_args
=
"
%
s --list
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_prog_path"
),
self
.
systemServiceName
())
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
self
.
execProcess
(
proc_args
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
if
proc_returncode
!=
0
:
raise
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
service_record_list
=
re
.
split
(
r"\s+"
,
proc_stdout
.
split
(
"
\n
"
)[
0
])
service_record_list
=
re
.
split
(
r"\s+"
,
proc_stdout
.
split
(
"
\n
"
)[
0
])
...
@@ -78,16 +72,16 @@ class SystemService(service.FunctionObject) :
...
@@ -78,16 +72,16 @@ class SystemService(service.FunctionObject) :
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
start
(
self
)
:
def
start
(
self
)
:
logger
.
verbose
(
"{mod}: Request to start service
\"
%
s
\"
"
%
(
self
.
systemServiceName
()))
logger
.
verbose
(
"{mod}: Request to start service
\"
%
s
\"
"
%
(
self
.
systemServiceName
()))
return
self
.
execProcess
(
"
%
s start"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
systemServiceName
())))[
2
]
return
tools
.
execProcess
(
"
%
s start"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
systemServiceName
())))[
2
]
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
stop
(
self
)
:
def
stop
(
self
)
:
return
self
.
execProcess
(
"
%
s stop"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
systemServiceName
())))[
2
]
return
tools
.
execProcess
(
"
%
s stop"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
systemServiceName
())))[
2
]
logger
.
verbose
(
"{mod}: Request to stop service
\"
%
s
\"
"
%
(
self
.
systemServiceName
()))
logger
.
verbose
(
"{mod}: Request to stop service
\"
%
s
\"
"
%
(
self
.
systemServiceName
()))
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
status
(
self
)
:
def
status
(
self
)
:
return
self
.
execProcess
(
"
%
s status"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
systemServiceName
())))[
2
]
return
tools
.
execProcess
(
"
%
s status"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir_path"
),
self
.
systemServiceName
())))[
2
]
### Private ###
### Private ###
...
@@ -105,39 +99,27 @@ class SystemService(service.FunctionObject) :
...
@@ -105,39 +99,27 @@ class SystemService(service.FunctionObject) :
proc_args
=
"
%
s
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_prog_path"
),
(
"--level
%
s"
%
(
levels
)
if
levels
!=
None
else
""
),
proc_args
=
"
%
s
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_prog_path"
),
(
"--level
%
s"
%
(
levels
)
if
levels
!=
None
else
""
),
self
.
systemServiceName
(),
(
"on"
if
enabled_flag
else
"off"
)
)
self
.
systemServiceName
(),
(
"on"
if
enabled_flag
else
"off"
)
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
self
.
execProcess
(
proc_args
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
if
proc_returncode
!=
0
:
if
proc_returncode
!=
0
:
raise
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
raise
tools
.
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
proc_returncode
return
proc_returncode
###
###
def
execProcess
(
self
,
proc_args
)
:
logger
.
debug
(
"{mod}: Executing child process
\"
%
s
\"
"
%
(
proc_args
))
proc
=
subprocess
.
Popen
(
proc_args
,
shell
=
True
,
bufsize
=
1024
,
close_fds
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
{
"LC_ALL"
:
"C"
})
(
proc_stdout
,
proc_stderr
)
=
proc
.
communicate
()
logger
.
debug
(
"{mod}: Child process
\"
%
s
\"
finished, return_code=
%
d"
%
(
proc_args
,
proc
.
returncode
))
return
(
proc_stdout
,
proc_stderr
,
proc
.
returncode
)
###
def
validateLevels
(
self
,
levels
)
:
def
validateLevels
(
self
,
levels
)
:
if
type
(
levels
)
.
__name__
in
(
"str"
,
"String"
)
:
if
type
(
levels
)
.
__name__
in
(
"str"
,
"String"
)
:
if
len
(
levels
)
==
0
:
if
len
(
levels
)
==
0
:
levels
=
None
levels
=
None
for
level
in
levels
:
for
level
in
levels
:
if
not
level
in
RUNLEVELS
:
if
not
level
in
RUNLEVELS
:
raise
IncorrectArgument
(
"Incorrect item
\"
%
s
\"
in argument
\"
%
s
\"
"
%
(
level
,
levels
))
raise
validators
.
ValidatorError
(
"Incorrect item
\"
%
s
\"
in argument
\"
%
s
\"
"
%
(
level
,
levels
))
elif
type
(
levels
)
.
__name__
==
"NoneType"
:
elif
type
(
levels
)
.
__name__
==
"NoneType"
:
pass
pass
else
:
else
:
raise
IncorrectArgument
(
"Incorrect type
\"
%
s
\"
of argument"
%
(
type
(
levels
)
.
__name__
))
raise
validators
.
ValidatorError
(
"Incorrect type
\"
%
s
\"
of argument"
%
(
type
(
levels
)
.
__name__
))
return
levels
return
levels
...
@@ -148,17 +130,7 @@ class Service(service.Service) :
...
@@ -148,17 +130,7 @@ class Service(service.Service) :
def
initService
(
self
)
:
def
initService
(
self
)
:
proc_args
=
"
%
s --list"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_prog_path"
))
proc_args
=
"
%
s --list"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_prog_path"
))
(
proc_stdout
,
proc_sterr
,
proc_returncode
)
=
tools
.
execProcess
(
proc_args
)
logger
.
debug
(
"{mod}: Executing child process
\"
%
s
\"
"
%
(
proc_args
))
proc
=
subprocess
.
Popen
(
proc_args
,
shell
=
True
,
bufsize
=
1024
,
close_fds
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
{
"LC_ALL"
:
"C"
})
(
proc_stdout
,
proc_stderr
)
=
proc
.
communicate
()
logger
.
debug
(
"{mod}: Child process
\"
%
s
\"
finished, return_code=
%
d"
%
(
proc_args
,
proc
.
returncode
))
if
proc
.
returncode
!=
0
:
raise
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc
.
returncode
))
system_service_count
=
0
system_service_count
=
0
shared
.
Functions
.
addShared
(
SERVICE_NAME
)
shared
.
Functions
.
addShared
(
SERVICE_NAME
)
...
...
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