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
38c5f0b9
Commit
38c5f0b9
authored
Feb 03, 2011
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Config options refactoring
parent
52b4069a
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
103 additions
and
106 deletions
+103
-106
fmod_common_info.py
plugins/functions/fmod_common_info.py
+4
-4
fmod_date_time.py
plugins/functions/fmod_date_time.py
+20
-20
fmod_disks_smart.py
plugins/functions/fmod_disks_smart.py
+4
-4
fmod_dnsmasq_config.py
plugins/functions/fmod_dnsmasq_config.py
+7
-7
fmod_local_groups.py
plugins/functions/fmod_local_groups.py
+17
-17
fmod_local_users.py
plugins/functions/fmod_local_users.py
+20
-21
fmod_machine.py
plugins/functions/fmod_machine.py
+12
-12
fmod_ntp_config.py
plugins/functions/fmod_ntp_config.py
+6
-7
fmod_rtorrentd_config.py
plugins/functions/fmod_rtorrentd_config.py
+4
-5
fmod_system_services.py
plugins/functions/fmod_system_services.py
+9
-9
No files found.
plugins/functions/fmod_common_info.py
View file @
38c5f0b9
...
...
@@ -95,11 +95,11 @@ class CommonInfo(service.FunctionObject) :
### Private ###
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_
bin
"
),
option
)
return
":"
.
join
(
tools
.
process
.
execProcess
(
proc_args
)[
0
]
.
split
(
":"
)[
1
:])
.
strip
()
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_
bin
"
),
option
)
return
tools
.
process
.
execProcess
(
proc_args
)[
0
]
.
strip
()
...
...
@@ -120,7 +120,7 @@ class Service(service.Service) :
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"lsb_release_
prog_path
"
,
"/usr/bin/lsb_release"
,
str
),
(
SERVICE_NAME
,
"uname_
prog_path
"
,
"/bin/uname"
,
str
)
(
SERVICE_NAME
,
"lsb_release_
bin
"
,
"/usr/bin/lsb_release"
,
str
),
(
SERVICE_NAME
,
"uname_
bin
"
,
"/bin/uname"
,
str
)
]
plugins/functions/fmod_date_time.py
View file @
38c5f0b9
...
...
@@ -37,7 +37,7 @@ class DateTime(service.FunctionObject) :
@service.functionMethod
(
SYSTEM_CLOCK_METHODS_NAMESPACE
,
in_signature
=
"iiiiii"
,
out_signature
=
"i"
)
def
setUtcTime
(
self
,
month
,
monthday
,
hour
,
minute
,
year
,
second
)
:
proc_args
=
"
%
s -u
%02
d
%02
d
%02
d
%02
d
%04
d.
%02
d"
%
(
config
.
value
(
SERVICE_NAME
,
"date_
prog_path
"
),
proc_args
=
"
%
s -u
%02
d
%02
d
%02
d
%02
d
%04
d.
%02
d"
%
(
config
.
value
(
SERVICE_NAME
,
"date_
bin
"
),
month
,
monthday
,
hour
,
minute
,
year
,
second
)
return
tools
.
process
.
execProcess
(
proc_args
,
False
)[
2
]
...
...
@@ -50,35 +50,35 @@ class DateTime(service.FunctionObject) :
@service.functionMethod
(
ZONE_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
setTimeZone
(
self
,
zone
)
:
if
not
os
.
access
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir
_path
"
),
zone
),
os
.
F_OK
)
:
if
not
os
.
access
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir"
),
zone
),
os
.
F_OK
)
:
raise
InvalidTimeZone
(
"Unknown time zone
\"
%
s
\"
"
%
(
zone
))
os
.
remove
(
config
.
value
(
SERVICE_NAME
,
"localtime_file
_path
"
))
os
.
symlink
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir
_path
"
),
zone
),
config
.
value
(
SERVICE_NAME
,
"localtime_file
_path
"
))
os
.
remove
(
config
.
value
(
SERVICE_NAME
,
"localtime_file"
))
os
.
symlink
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir"
),
zone
),
config
.
value
(
SERVICE_NAME
,
"localtime_file"
))
time_zone_editor
=
tools
.
editors
.
PlainEditor
(
spaces_list
=
[])
time_zone_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"clock_conf
ig_file_path
"
),
config
.
value
(
SERVICE_NAME
,
"
sample_clock_config_file_path
"
))
time_zone_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"clock_conf"
),
config
.
value
(
SERVICE_NAME
,
"
clock_conf_sample
"
))
time_zone_editor
.
setValue
(
"ZONE"
,
zone
)
time_zone_editor
.
save
()
time_zone_editor
.
close
()
@service.functionMethod
(
ZONE_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
timeZone
(
self
)
:
if
os
.
access
(
config
.
value
(
SERVICE_NAME
,
"clock_conf
ig_file_path
"
),
os
.
F_OK
)
:
if
os
.
access
(
config
.
value
(
SERVICE_NAME
,
"clock_conf"
),
os
.
F_OK
)
:
time_zone_editor
=
tools
.
editors
.
PlainEditor
(
spaces_list
=
[])
time_zone_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"clock_conf
ig_file_path
"
))
time_zone_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"clock_conf"
))
zones_list
=
time_zone_editor
.
value
(
"ZONE"
)
time_zone_editor
.
close
()
if
len
(
zones_list
)
>
0
:
return
os
.
path
.
normpath
(
zones_list
[
-
1
])
try
:
zoneinfo_dir_path
=
os
.
path
.
normpath
(
os
.
readlink
(
config
.
value
(
SERVICE_NAME
,
"localtime_file
_path
"
)))
zoneinfo_dir_path
=
os
.
path
.
normpath
(
os
.
readlink
(
config
.
value
(
SERVICE_NAME
,
"localtime_file"
)))
except
:
zoneinfo_cache_dict
=
{}
for
(
root_dir_path
,
dirs_list
,
files_list
)
in
os
.
walk
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir
_path
"
))
:
for
(
root_dir_path
,
dirs_list
,
files_list
)
in
os
.
walk
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir"
))
:
for
files_list_item
in
files_list
:
zone_file_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
root_dir_path
,
files_list_item
))
zone_file
=
open
(
zone_file_path
)
...
...
@@ -87,7 +87,7 @@ class DateTime(service.FunctionObject) :
zone_file
.
close
()
except
:
pass
zone_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"localtime_file
_path
"
))
zone_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"localtime_file"
))
zone_file_hash
=
hashlib
.
sha1
(
zone_file
.
read
())
.
hexdigest
()
try
:
zone_file
.
close
()
...
...
@@ -95,14 +95,14 @@ class DateTime(service.FunctionObject) :
zoneinfo_dir_path
=
(
zoneinfo_cache_dict
[
zone_file_hash
]
if
zoneinfo_cache_dict
.
has_key
(
zone_file_hash
)
else
""
)
zoneinfo_dir_path_regexp_str
=
r"^
%
s/+(.*)"
%
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir
_path
"
))
zoneinfo_dir_path_regexp_str
=
r"^
%
s/+(.*)"
%
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir"
))
return
os
.
path
.
normpath
(
re
.
sub
(
zoneinfo_dir_path_regexp_str
,
r"\1"
,
zoneinfo_dir_path
))
###
@service.functionMethod
(
HARDWARE_CLOCK_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
syncWithSystem
(
self
)
:
return
tools
.
process
.
execProcess
(
"
%
s --systohc"
%
(
config
.
value
(
SERVICE_NAME
,
"hwclock_
prog_path
"
)),
False
)[
0
]
return
tools
.
process
.
execProcess
(
"
%
s --systohc"
%
(
config
.
value
(
SERVICE_NAME
,
"hwclock_
bin
"
)),
False
)[
0
]
##### Public classes #####
...
...
@@ -123,12 +123,12 @@ class Service(service.Service) :
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"date_
prog_path
"
,
"/bin/date"
,
str
),
(
SERVICE_NAME
,
"hwclock_
prog_path
"
,
"/usr/sbin/hwclock"
,
str
),
(
SERVICE_NAME
,
"localtime_file
_path
"
,
"/etc/localtime"
,
str
),
(
SERVICE_NAME
,
"zoneinfo_dir
_path
"
,
"/usr/share/zoneinfo"
,
str
),
(
SERVICE_NAME
,
"clock_conf
ig_file_path
"
,
"/etc/sysconfig/clock"
,
str
),
(
SERVICE_NAME
,
"date_
bin
"
,
"/bin/date"
,
str
),
(
SERVICE_NAME
,
"hwclock_
bin
"
,
"/usr/sbin/hwclock"
,
str
),
(
SERVICE_NAME
,
"localtime_file"
,
"/etc/localtime"
,
str
),
(
SERVICE_NAME
,
"zoneinfo_dir"
,
"/usr/share/zoneinfo"
,
str
),
(
SERVICE_NAME
,
"clock_conf"
,
"/etc/sysconfig/clock"
,
str
),
(
SERVICE_NAME
,
"
sample_clock_config_file_path
"
,
os
.
path
.
join
(
const
.
FUNCTIONS_DATA_DIR
,
SERVICE_NAME
,
"clock"
),
str
)
(
SERVICE_NAME
,
"
clock_conf_sample
"
,
os
.
path
.
join
(
const
.
FUNCTIONS_DATA_DIR
,
SERVICE_NAME
,
"clock"
),
str
)
]
plugins/functions/fmod_disks_smart.py
View file @
38c5f0b9
...
...
@@ -38,7 +38,7 @@ class Disk(service.FunctionObject) :
@service.functionMethod
(
SMART_METHODS_NAMESPACE
,
out_signature
=
"a(isiiiissss)"
)
def
attributes
(
self
)
:
proc_args
=
"
%
s -A
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_
prog_path
"
),
self
.
__device_file_path
)
proc_args
=
"
%
s -A
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_
bin
"
),
self
.
__device_file_path
)
attrs_list
=
[]
attrs_found_flag
=
False
...
...
@@ -65,7 +65,7 @@ class Disk(service.FunctionObject) :
@service.functionMethod
(
SMART_METHODS_NAMESPACE
,
out_signature
=
"b"
)
def
health
(
self
)
:
proc_args
=
"
%
s -H
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_
prog_path
"
),
self
.
__device_file_path
)
proc_args
=
"
%
s -H
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_
bin
"
),
self
.
__device_file_path
)
disk_health_flag
=
False
health_found_flag
=
False
...
...
@@ -135,14 +135,14 @@ class Service(service.Service) :
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"disks_filter"
,
"^[(sd)(hd)][a-z]+$"
,
str
),
(
SERVICE_NAME
,
"smartctl_
prog_path
"
,
"/usr/sbin/smartctl"
,
str
)
(
SERVICE_NAME
,
"smartctl_
bin
"
,
"/usr/sbin/smartctl"
,
str
)
]
### Private ###
def
smartAvailable
(
self
,
device_file_path
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_
prog_path
"
),
device_file_path
)
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"smartctl_
bin
"
),
device_file_path
)
return
not
bool
(
tools
.
process
.
execProcess
(
proc_args
,
False
)[
2
])
###
...
...
plugins/functions/fmod_dnsmasq_config.py
View file @
38c5f0b9
...
...
@@ -91,8 +91,8 @@ class SimpleDnsmasqConfig(service.FunctionObject) :
static_host
+=
(
",
%
s"
%
(
name
)
if
len
(
name
)
!=
0
else
""
)
dnsmasq_editor
=
tools
.
editors
.
PlainEditor
(
spaces_list
=
[],
quotes_list
=
[])
dnsmasq_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"dnsmasq_conf
ig_file_path
"
),
config
.
value
(
SERVICE_NAME
,
"
sample_dnsmasq_config_file_path
"
))
dnsmasq_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"dnsmasq_conf"
),
config
.
value
(
SERVICE_NAME
,
"
dnsmasq_conf_sample
"
))
dnsmasq_editor
.
setValue
(
"dhcp-host"
,
dnsmasq_editor
.
value
(
"dhcp_host"
)
+
[
static_host
])
dnsmasq_editor
.
save
()
dnsmasq_editor
.
close
()
...
...
@@ -145,15 +145,15 @@ class SimpleDnsmasqConfig(service.FunctionObject) :
def
setConfigValue
(
self
,
variable_name
,
values_list
)
:
dnsmasq_editor
=
tools
.
editors
.
PlainEditor
(
spaces_list
=
[],
quotes_list
=
[])
dnsmasq_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"dnsmasq_conf
ig_file_path
"
),
config
.
value
(
SERVICE_NAME
,
"
sample_dnsmasq_config_file_path
"
))
dnsmasq_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"dnsmasq_conf"
),
config
.
value
(
SERVICE_NAME
,
"
dnsmasq_conf_sample
"
))
dnsmasq_editor
.
setValue
(
variable_name
,
values_list
)
dnsmasq_editor
.
save
()
dnsmasq_editor
.
close
()
def
configValue
(
self
,
variable_name
)
:
dnsmasq_editor
=
tools
.
editors
.
PlainEditor
(
spaces_list
=
[],
quotes_list
=
[])
dnsmasq_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"dnsmasq_conf
ig_file_path
"
))
dnsmasq_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"dnsmasq_conf"
))
values_list
=
dnsmasq_editor
.
value
(
variable_name
)
dnsmasq_editor
.
close
()
return
values_list
...
...
@@ -177,8 +177,8 @@ class Service(service.Service) :
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"dnsmasq_conf
ig_file_path
"
,
"/etc/dnsmasq.conf"
,
str
),
(
SERVICE_NAME
,
"dnsmasq_conf"
,
"/etc/dnsmasq.conf"
,
str
),
(
SERVICE_NAME
,
"
sample_dnsmasq_config_file_path
"
,
os
.
path
.
join
(
const
.
FUNCTIONS_DATA_DIR
,
SERVICE_NAME
,
"dnsmasq.conf"
),
str
)
(
SERVICE_NAME
,
"
dnsmasq_conf_sample
"
,
os
.
path
.
join
(
const
.
FUNCTIONS_DATA_DIR
,
SERVICE_NAME
,
"dnsmasq.conf"
),
str
)
]
plugins/functions/fmod_local_groups.py
View file @
38c5f0b9
...
...
@@ -54,7 +54,7 @@ class LocalGroup(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change gid for local group
\"
%
s
\"
, new gid=
%
d"
%
(
self
.
__group_name
,
gid
))
return
tools
.
process
.
execProcess
(
"
%
s -g
%
d
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"groupmod_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s -g
%
d
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"groupmod_
bin
"
),
gid
,
self
.
__group_name
),
False
)[
2
]
@service.functionMethod
(
LOCAL_GROUP_METHODS_NAMESPACE
,
out_signature
=
"i"
)
...
...
@@ -68,7 +68,7 @@ class LocalGroup(service.FunctionObject) :
user_name
=
validators
.
os
.
validUserName
(
user_name
)
logger
.
verbose
(
"{mod}: Request to add user
\"
%
s
\"
to local group
\"
%
s
\"
"
%
(
user_name
,
self
.
__group_name
))
return
tools
.
process
.
execProcess
(
"
%
s -a -G
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s -a -G
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
bin
"
),
self
.
__group_name
,
user_name
),
False
)[
2
]
@service.functionMethod
(
LOCAL_GROUP_METHODS_NAMESPACE
,
in_signature
=
"s"
,
out_signature
=
"i"
)
...
...
@@ -79,7 +79,7 @@ class LocalGroup(service.FunctionObject) :
users_list
.
remove
(
self
.
__group_name
)
logger
.
verbose
(
"{mod}: Request to remove user
\"
%
s
\"
from local group
\"
%
s
\"
"
%
(
user_name
,
self
.
__group_name
))
return
tools
.
process
.
execProcess
(
"
%
s -G
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s -G
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
bin
"
),
","
.
join
(
users_list
),
user_name
),
False
)[
2
]
@service.functionMethod
(
LOCAL_GROUP_METHODS_NAMESPACE
,
out_signature
=
"as"
)
...
...
@@ -98,14 +98,14 @@ class LocalGroups(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to add local group
\"
%
s
\"
with gid=
%
s"
%
(
group_name
,
gid_str
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"groupadd_
prog_path
"
),
gid_arg
,
group_name
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"groupadd_
bin
"
),
gid_arg
,
group_name
))
@service.functionMethod
(
LOCAL_GROUPS_METHODS_NAMESPACE
,
in_signature
=
"s"
,
out_signature
=
"i"
)
def
removeGroup
(
self
,
group_name
)
:
group_name
=
validators
.
os
.
validGroupName
(
group_name
)
logger
.
verbose
(
"{mod}: Request to remove local group
\"
%
s
\"
"
%
(
group_name
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"groupdel_
prog_path
"
),
group_name
),
False
)[
2
]
return
tools
.
process
.
execProcess
(
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"groupdel_
bin
"
),
group_name
),
False
)[
2
]
###
...
...
@@ -137,7 +137,7 @@ class LocalGroups(service.FunctionObject) :
def
loginDefsValue
(
self
,
variable_name
)
:
editor
=
tools
.
editors
.
PlainEditor
(
delimiter
=
""
,
quotes_list
=
[])
editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"login_defs_conf
ig_file_path
"
))
editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"login_defs_conf"
))
values_list
=
editor
.
value
(
variable_name
)
editor
.
close
()
return
(
int
(
values_list
[
-
1
])
if
len
(
values_list
)
>
0
else
-
1
)
...
...
@@ -173,13 +173,13 @@ class Service(service.Service, pyinotify.ThreadedNotifier) :
group_count
+=
1
logger
.
verbose
(
"{mod}: Added
%
d local groups"
%
(
group_count
))
group_config_subdir_path
=
os
.
path
.
dirname
(
config
.
value
(
SERVICE_NAME
,
"group_conf
ig_file_path
"
))
group_config_subdir_path
=
os
.
path
.
dirname
(
config
.
value
(
SERVICE_NAME
,
"group_conf"
))
self
.
__watch_manager
.
add_watch
(
group_config_subdir_path
,
pyinotify
.
IN_DELETE
|
pyinotify
.
IN_CREATE
|
pyinotify
.
IN_MOVED_TO
,
rec
=
True
)
self
.
start
()
logger
.
verbose
(
"{mod}: Start polling inotify events for
\"
%
s
\"
"
%
(
group_config_subdir_path
))
def
closeService
(
self
)
:
group_config_subdir_path
=
os
.
path
.
dirname
(
config
.
value
(
SERVICE_NAME
,
"group_conf
ig_file_path
"
))
group_config_subdir_path
=
os
.
path
.
dirname
(
config
.
value
(
SERVICE_NAME
,
"group_conf"
))
self
.
__watch_manager
.
rm_watch
(
self
.
__watch_manager
.
get_wd
(
group_config_subdir_path
))
self
.
stop
()
logger
.
verbose
(
"{mod}: Stop polling inotify events for
\"
%
s
\"
"
%
(
group_config_subdir_path
))
...
...
@@ -193,20 +193,20 @@ class Service(service.Service, pyinotify.ThreadedNotifier) :
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"groupadd_
prog_path
"
,
"/usr/sbin/groupadd"
,
str
),
(
SERVICE_NAME
,
"groupdel_
prog_path
"
,
"/usr/sbin/groupdel"
,
str
),
(
SERVICE_NAME
,
"groupmod_
prog_path
"
,
"/usr/sbin/groupmod"
,
str
),
(
SERVICE_NAME
,
"usermod_
prog_path
"
,
"/usr/sbin/usermod"
,
str
),
(
SERVICE_NAME
,
"group_conf
ig_file_path
"
,
"/etc/group"
,
str
),
(
SERVICE_NAME
,
"login_defs_conf
ig_file_path
"
,
"/etc/login.defs"
,
str
)
(
SERVICE_NAME
,
"groupadd_
bin
"
,
"/usr/sbin/groupadd"
,
str
),
(
SERVICE_NAME
,
"groupdel_
bin
"
,
"/usr/sbin/groupdel"
,
str
),
(
SERVICE_NAME
,
"groupmod_
bin
"
,
"/usr/sbin/groupmod"
,
str
),
(
SERVICE_NAME
,
"usermod_
bin
"
,
"/usr/sbin/usermod"
,
str
),
(
SERVICE_NAME
,
"group_conf"
,
"/etc/group"
,
str
),
(
SERVICE_NAME
,
"login_defs_conf"
,
"/etc/login.defs"
,
str
)
]
### Private ###
def
inotifyEvent
(
self
,
event
)
:
if
event
.
dir
or
not
event
.
pathname
in
(
config
.
value
(
SERVICE_NAME
,
"group_conf
ig_file_path
"
),
config
.
value
(
SERVICE_NAME
,
"login_defs_conf
ig_file_path
"
)
)
:
if
event
.
dir
or
not
event
.
pathname
in
(
config
.
value
(
SERVICE_NAME
,
"group_conf"
),
config
.
value
(
SERVICE_NAME
,
"login_defs_conf"
)
)
:
return
...
...
@@ -235,7 +235,7 @@ class Service(service.Service, pyinotify.ThreadedNotifier) :
def
localGroups
(
self
)
:
group_name_regexp
=
re
.
compile
(
r"(^[a-z_][a-z0-9_-]*):"
)
group_config_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"group_conf
ig_file_path
"
))
group_config_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"group_conf"
))
group_names_list
=
[]
for
group_record
in
group_config_file
.
read
()
.
split
(
"
\n
"
)
:
...
...
plugins/functions/fmod_local_users.py
View file @
38c5f0b9
...
...
@@ -55,7 +55,7 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change uid for local user
\"
%
s
\"
, new uid=
%
d"
%
(
self
.
__user_name
,
uid
))
return
tools
.
process
.
execProcess
(
"
%
s -u
%
d
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s -u
%
d
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
bin
"
),
uid
,
self
.
__user_name
),
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
...
...
@@ -71,7 +71,7 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change gid for local user
\"
%
s
\"
, new gid=
%
d"
%
(
self
.
__user_name
,
gid
))
return
tools
.
process
.
execProcess
(
"
%
s -g
%
d
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s -g
%
d
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
bin
"
),
gid
,
self
.
__user_name
),
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
...
...
@@ -87,7 +87,7 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change home for local user
\"
%
s
\"
, new home=
\"
%
s
\"
"
%
(
self
.
__user_name
,
path
))
return
tools
.
process
.
execProcess
(
"
%
s -d
\'
%
s
\'
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s -d
\'
%
s
\'
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
bin
"
),
path
,
self
.
__user_name
),
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"s"
)
...
...
@@ -101,7 +101,7 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change shell for local user
\"
%
s
\"
, new shell=
\"
%
s
\"
"
%
(
self
.
__user_name
,
path
))
return
tools
.
process
.
execProcess
(
"
%
s -s
\'
%
s
\'
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s -s
\'
%
s
\'
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
bin
"
),
path
,
self
.
__user_name
),
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"s"
)
...
...
@@ -117,7 +117,7 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to change comment for local user
\"
%
s
\"
, new comment=
\"
%
s
\"
"
%
(
self
.
__user_name
,
text
))
return
tools
.
process
.
execProcess
(
"
%
s -c
\'
%
s
\'
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s -c
\'
%
s
\'
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
bin
"
),
text
,
self
.
__user_name
),
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"s"
)
...
...
@@ -132,7 +132,7 @@ class LocalUser(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to
%
s local user
\"
%
s
\"
"
%
(
lock_str
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"usermod_
bin
"
),
lock_arg
,
self
.
__user_name
),
False
)[
2
]
@service.functionMethod
(
LOCAL_USER_METHODS_NAMESPACE
,
out_signature
=
"b"
)
...
...
@@ -156,7 +156,7 @@ class LocalUsers(service.FunctionObject) :
logger
.
verbose
(
"{mod}: Request to add local user
\"
%
s
\"
with uid=
%
s and gid=
%
s"
%
(
user_name
,
uid_str
,
gid_str
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"useradd_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"useradd_
bin
"
),
uid_arg
,
gid_arg
,
user_name
))
@service.functionMethod
(
LOCAL_USERS_METHODS_NAMESPACE
,
in_signature
=
"sb"
,
out_signature
=
"i"
)
...
...
@@ -165,7 +165,7 @@ class LocalUsers(service.FunctionObject) :
(
remove_data_arg
,
remove_data_str
)
=
(
(
"-r"
,
" and its data"
)
if
remove_data_flag
else
(
""
,
""
)
)
logger
.
verbose
(
"{mod}: Request to remove local user
\"
%
s
\"
%
s"
%
(
user_name
,
remove_data_str
))
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"userdel_
prog_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"userdel_
bin
"
),
remove_data_arg
,
user_name
),
False
)[
2
]
###
...
...
@@ -198,7 +198,7 @@ class LocalUsers(service.FunctionObject) :
def
loginDefsValue
(
self
,
variable_name
)
:
editor
=
tools
.
editors
.
PlainEditor
(
delimiter
=
""
,
quotes_list
=
[])
editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"login_defs_conf
ig_file_path
"
))
editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"login_defs_conf"
))
values_list
=
editor
.
value
(
variable_name
)
editor
.
close
()
return
(
int
(
values_list
[
-
1
])
if
len
(
values_list
)
>
0
else
-
1
)
...
...
@@ -234,13 +234,13 @@ class Service(service.Service, pyinotify.ThreadedNotifier) :
user_count
+=
1
logger
.
verbose
(
"{mod}: Added
%
d local users"
%
(
user_count
))
passwd_config_subdir_path
=
os
.
path
.
dirname
(
config
.
value
(
SERVICE_NAME
,
"passwd_conf
ig_file_path
"
))
passwd_config_subdir_path
=
os
.
path
.
dirname
(
config
.
value
(
SERVICE_NAME
,
"passwd_conf"
))
self
.
__watch_manager
.
add_watch
(
passwd_config_subdir_path
,
pyinotify
.
IN_DELETE
|
pyinotify
.
IN_CREATE
|
pyinotify
.
IN_MOVED_TO
,
rec
=
True
)
self
.
start
()
logger
.
verbose
(
"{mod}: Start polling inotify events for
\"
%
s
\"
"
%
(
passwd_config_subdir_path
))
def
closeService
(
self
)
:
passwd_config_subdir_path
=
os
.
path
.
dirname
(
config
.
value
(
SERVICE_NAME
,
"passwd_conf
ig_file_path
"
))
passwd_config_subdir_path
=
os
.
path
.
dirname
(
config
.
value
(
SERVICE_NAME
,
"passwd_conf"
))
self
.
__watch_manager
.
rm_watch
(
self
.
__watch_manager
.
get_wd
(
passwd_config_subdir_path
))
self
.
stop
()
logger
.
verbose
(
"{mod}: Stop polling inotify events for
\"
%
s
\"
"
%
(
passwd_config_subdir_path
))
...
...
@@ -254,21 +254,20 @@ class Service(service.Service, pyinotify.ThreadedNotifier) :
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"useradd_
prog_path
"
,
"/usr/sbin/useradd"
,
str
),
(
SERVICE_NAME
,
"userdel_
prog_path
"
,
"/usr/sbin/userdel"
,
str
),
(
SERVICE_NAME
,
"usermod_
prog_path
"
,
"/usr/sbin/usermod"
,
str
),
(
SERVICE_NAME
,
"passwd_conf
ig_file_path
"
,
"/etc/passwd"
,
str
),
(
SERVICE_NAME
,
"shadow_conf
ig_file_path
"
,
"/etc/shadow"
,
str
),
(
SERVICE_NAME
,
"login_defs_conf
ig_file_path
"
,
"/etc/login.defs"
,
str
)
(
SERVICE_NAME
,
"useradd_
bin
"
,
"/usr/sbin/useradd"
,
str
),
(
SERVICE_NAME
,
"userdel_
bin
"
,
"/usr/sbin/userdel"
,
str
),
(
SERVICE_NAME
,
"usermod_
bin
"
,
"/usr/sbin/usermod"
,
str
),
(
SERVICE_NAME
,
"passwd_conf"
,
"/etc/passwd"
,
str
),
(
SERVICE_NAME
,
"shadow_conf"
,
"/etc/shadow"
,
str
),
(
SERVICE_NAME
,
"login_defs_conf"
,
"/etc/login.defs"
,
str
)
]
### Private ###
def
inotifyEvent
(
self
,
event
)
:
if
event
.
dir
or
not
event
.
pathname
in
(
config
.
value
(
SERVICE_NAME
,
"passwd_config_file_path"
),
config
.
value
(
SERVICE_NAME
,
"shadow_config_file_path"
),
config
.
value
(
SERVICE_NAME
,
"login_defs_config_file_path"
)
)
:
if
event
.
dir
or
not
event
.
pathname
in
(
config
.
value
(
SERVICE_NAME
,
"passwd_conf"
),
config
.
value
(
SERVICE_NAME
,
"shadow_conf"
),
config
.
value
(
SERVICE_NAME
,
"login_defs_conf"
)
)
:
return
...
...
@@ -297,7 +296,7 @@ class Service(service.Service, pyinotify.ThreadedNotifier) :
def
localUsers
(
self
)
:
user_name_regexp
=
re
.
compile
(
r"(^[a-z_][a-z0-9_-]*):"
)
passwd_config_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"passwd_conf
ig_file_path
"
))
passwd_config_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"passwd_conf"
))
user_names_list
=
[]
for
passwd_record
in
passwd_config_file
.
read
()
.
split
(
"
\n
"
)
:
...
...
plugins/functions/fmod_machine.py
View file @
38c5f0b9
...
...
@@ -29,30 +29,30 @@ class Machine(service.FunctionObject) :
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
shutdown
(
self
)
:
return
tools
.
process
.
execProcess
(
"
%
s -h now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_
prog_path
"
)),
False
)[
2
]
return
tools
.
process
.
execProcess
(
"
%
s -h now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_
bin
"
)),
False
)[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
reboot
(
self
)
:
return
tools
.
process
.
execProcess
(
"
%
s -r now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_
prog_path
"
)),
False
)[
2
]
return
tools
.
process
.
execProcess
(
"
%
s -r now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_
bin
"
)),
False
)[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
suspend
(
self
)
:
return
tools
.
process
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_suspend_
prog_path
"
),
False
)[
2
]
return
tools
.
process
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_suspend_
bin
"
),
False
)[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
hibernate
(
self
)
:
return
tools
.
process
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_hibernate_
prog_path
"
),
False
)[
2
]
return
tools
.
process
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_hibernate_
bin
"
),
False
)[
2
]
###
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
in_signature
=
"i"
,
out_signature
=
"i"
)
def
switchTo
(
self
,
level
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"telinit_
prog_path
"
),
validators
.
common
.
validRange
(
str
(
level
),
RUNLEVELS
))
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"telinit_
bin
"
),
validators
.
common
.
validRange
(
str
(
level
),
RUNLEVELS
))
return
tools
.
process
.
execProcess
(
proc_args
,
False
)[
2
]
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
currentLevel
(
self
)
:
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_
prog_path
"
)
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_
bin
"
)
level_pairs_list
=
tools
.
process
.
execProcess
(
proc_args
)[
0
]
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
:
...
...
@@ -63,7 +63,7 @@ class Machine(service.FunctionObject) :
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
previousLevel
(
self
)
:
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_
prog_path
"
)
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_
bin
"
)
level_pairs_list
=
tools
.
process
.
execProcess
(
proc_args
)[
0
]
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
+
"N"
:
...
...
@@ -90,10 +90,10 @@ class Service(service.Service) :
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"shutdown_
prog_path
"
,
"/sbin/shutdown"
,
str
),
(
SERVICE_NAME
,
"pm_suspend_
prog_path
"
,
"/usr/sbin/pm-suspend"
,
str
),
(
SERVICE_NAME
,
"pm_hibernate_
prog_path
"
,
"/usr/sbin/pm-hibernate"
,
str
),
(
SERVICE_NAME
,
"telinit_
prog_path
"
,
"/sbin/telinit"
,
str
),
(
SERVICE_NAME
,
"runlevel_
prog_path
"
,
"/sbin/runlevel"
,
str
)
(
SERVICE_NAME
,
"shutdown_
bin
"
,
"/sbin/shutdown"
,
str
),
(
SERVICE_NAME
,
"pm_suspend_
bin
"
,
"/usr/sbin/pm-suspend"
,
str
),
(
SERVICE_NAME
,
"pm_hibernate_
bin
"
,
"/usr/sbin/pm-hibernate"
,
str
),
(
SERVICE_NAME
,
"telinit_
bin
"
,
"/sbin/telinit"
,
str
),
(
SERVICE_NAME
,
"runlevel_
bin
"
,
"/sbin/runlevel"
,
str
)
]
plugins/functions/fmod_ntp_config.py
View file @
38c5f0b9
...
...
@@ -29,8 +29,7 @@ class NtpConfig(service.FunctionObject) :
@service.functionMethod
(
NTP_METHODS_NAMESPACE
,
in_signature
=
"as"
)
def
setServers
(
self
,
servers_list
)
:
ntp_editor
=
tools
.
editors
.
PlainEditor
(
delimiter
=
""
,
quotes_list
=
[])
ntp_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"ntp_config_file_path"
),
config
.
value
(
SERVICE_NAME
,
"sample_ntp_config_file_path"
))
ntp_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"ntp_conf"
),
config
.
value
(
SERVICE_NAME
,
"ntp_conf_sample"
))
ntp_editor
.
setValue
(
"server"
,
servers_list
)
ntp_editor
.
save
()
ntp_editor
.
close
()
...
...
@@ -38,7 +37,7 @@ class NtpConfig(service.FunctionObject) :
@service.functionMethod
(
NTP_METHODS_NAMESPACE
,
out_signature
=
"as"
)
def
servers
(
self
)
:
ntp_editor
=
tools
.
editors
.
PlainEditor
(
delimiter
=
""
,
quotes_list
=
[])
ntp_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"ntp_conf
ig_file_path
"
))
ntp_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"ntp_conf"
))
servers_list
=
ntp_editor
.
value
(
"server"
)
ntp_editor
.
close
()
return
servers_list
...
...
@@ -47,7 +46,7 @@ class NtpConfig(service.FunctionObject) :
@service.functionMethod
(
NTP_METHODS_NAMESPACE
)
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_
bin
"
),
" "
.
join
(
self
.
servers
()))
tools
.
process
.
execProcess
(
proc_args
)
...
...
@@ -69,9 +68,9 @@ class Service(service.Service) :
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"ntpdate_
prog_path
"
,
"/usr/sbin/ntpdate"
,
str
),
(
SERVICE_NAME
,
"ntp_conf
ig_file_path
"
,
"/etc/ntp.conf"
,
str
),
(
SERVICE_NAME
,
"ntpdate_
bin
"
,
"/usr/sbin/ntpdate"
,
str
),
(
SERVICE_NAME
,
"ntp_conf"
,
"/etc/ntp.conf"
,
str
),
(
SERVICE_NAME
,
"
sample_ntp_config_file_path
"
,
os
.
path
.
join
(
const
.
FUNCTIONS_DATA_DIR
,
SERVICE_NAME
,
"ntp.conf"
),
str
)
(
SERVICE_NAME
,
"
ntp_conf_sample
"
,
os
.
path
.
join
(
const
.
FUNCTIONS_DATA_DIR
,
SERVICE_NAME
,
"ntp.conf"
),
str
)
]
plugins/functions/fmod_rtorrentd_config.py
View file @
38c5f0b9
...
...
@@ -164,15 +164,14 @@ class RTorrentd(service.FunctionObject) :
def
setConfigValue
(
self
,
variable_name
,
values_list
)
:
rtorrentd_editor
=
tools
.
editors
.
PlainEditor
(
spaces_list
=
[])
rtorrentd_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"rtorrentd_config_file_path"
),
config
.
value
(
SERVICE_NAME
,
"sample_rtorrentd_config_file_path"
))
rtorrentd_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"rtorrentd_conf"
),
config
.
value
(
SERVICE_NAME
,
"rtorrentd_conf_sample"
))
rtorrentd_editor
.
setValue
(
variable_name
,
values_list
)
rtorrentd_editor
.
save
()
rtorrentd_editor
.
close
()
def
configValue
(
self
,
variable_name
)
:
rtorrentd_editor
=
tools
.
editors
.
PlainEditor
(
spaces_list
=
[])
rtorrentd_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"rtorrentd_conf
ig_file_path
"
))
rtorrentd_editor
.
open
(
config
.
value
(
SERVICE_NAME
,
"rtorrentd_conf"
))
values_list
=
rtorrentd_editor
.
value
(
variable_name
)
rtorrentd_editor
.
close
()
return
values_list
...
...
@@ -196,8 +195,8 @@ class Service(service.Service) :
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"rtorrentd_conf
ig_file_path
"
,
"/etc/sysconfig/rtorrent"
,
str
),
(
SERVICE_NAME
,
"rtorrentd_conf"
,
"/etc/sysconfig/rtorrent"
,
str
),
(
SERVICE_NAME
,
"
sample_rtorrentd_config_file_path
"
,
os
.
path
.
join
(
const
.
FUNCTIONS_DATA_DIR
,
SERVICE_NAME
,
"rtorrent"
),
str
)
(
SERVICE_NAME
,
"
rtorrentd_conf_sample
"
,
os
.
path
.
join
(
const
.
FUNCTIONS_DATA_DIR
,
SERVICE_NAME
,
"rtorrent"
),
str
)
]
plugins/functions/fmod_system_services.py
View file @
38c5f0b9
...
...
@@ -55,7 +55,7 @@ class SystemService(service.FunctionObject) :
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
levelsMap
(
self
)
:
proc_args
=
"
%
s --list
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_
prog_path
"
),
self
.
__system_service_name
)
proc_args
=
"
%
s --list
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_
bin
"
),
self
.
__system_service_name
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
tools
.
process
.
execProcess
(
proc_args
)
service_record_list
=
re
.
split
(
r"\s+"
,
proc_stdout
.
split
(
"
\n
"
)[
0
])
...
...
@@ -81,18 +81,18 @@ class SystemService(service.FunctionObject) :
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
start
(
self
)
:
logger
.
verbose
(
"{mod}: Request to start service
\"
%
s
\"
"
%
(
self
.
__system_service_name
))
return
tools
.
process
.
execProcess
(
"
%
s start"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir
_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s start"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
)
),
False
)[
2
]
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
stop
(
self
)
:
logger
.
verbose
(
"{mod}: Request to stop service
\"
%
s
\"
"
%
(
self
.
__system_service_name
))
return
tools
.
process
.
execProcess
(
"
%
s stop"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir
_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s stop"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
)
),
False
)[
2
]
@service.functionMethod
(
SYSTEM_SERVICE_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
status
(
self
)
:
return
tools
.
process
.
execProcess
(
"
%
s status"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir
_path
"
),
return
tools
.
process
.
execProcess
(
"
%
s status"
%
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"initd_dir"
),
self
.
__system_service_name
)
),
False
)[
2
]
...
...
@@ -104,7 +104,7 @@ class SystemService(service.FunctionObject) :
logger
.
verbose
(
"Request to
%
s service
\"
%
s
\"
on runlevels
\"
%
s
\"
"
%
(
(
"enable"
if
enabled_flag
else
"disable"
),
self
.
__system_service_name
,
(
levels
if
levels
!=
None
else
"default"
)
))
proc_args
=
"
%
s
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_
prog_path
"
),
proc_args
=
"
%
s
%
s
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"chkconfig_
bin
"
),
(
"--level
%
s"
%
(
levels
)
if
levels
!=
None
else
""
),
self
.
__system_service_name
,
(
"on"
if
enabled_flag
else
"off"
)
)
return
tools
.
process
.
execProcess
(
proc_args
,
False
)[
2
]
...
...
@@ -151,7 +151,7 @@ class Service(service.Service, pyinotify.ThreadedNotifier) :
shared
.
Functions
.
addShared
(
SYSTEM_SERVICES_SHARED_NAME
)
shared
.
Functions
.
addSharedObject
(
SYSTEM_SERVICES_OBJECT_NAME
,
self
.
__system_services
)
initd_dir_path
=
config
.
value
(
SERVICE_NAME
,
"initd_dir
_path
"
)
initd_dir_path
=
config
.
value
(
SERVICE_NAME
,
"initd_dir"
)
logger
.
verbose
(
"{mod}: First services requset..."
)
system_services_shared
=
shared
.
Functions
.
shared
(
SYSTEM_SERVICES_SHARED_NAME
)
...
...
@@ -174,7 +174,7 @@ class Service(service.Service, pyinotify.ThreadedNotifier) :
logger
.
verbose
(
"{mod}: Start polling inotify events for
\"
%
s
\"
"
%
(
initd_dir_path
))
def
closeService
(
self
)
:
initd_dir_path
=
config
.
value
(
SERVICE_NAME
,
"initd_dir
_path
"
)
initd_dir_path
=
config
.
value
(
SERVICE_NAME
,
"initd_dir"
)
self
.
__watch_manager
.
rm_watch
(
self
.
__watch_manager
.
get_wd
(
initd_dir_path
))
self
.
stop
()
logger
.
verbose
(
"{mod}: Stop polling inotify events for
\"
%
s
\"
"
%
(
initd_dir_path
))
...
...
@@ -188,8 +188,8 @@ class Service(service.Service, pyinotify.ThreadedNotifier) :
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"initd_dir
_path
"
,
"/etc/rc.d/init.d"
,
str
),
(
SERVICE_NAME
,
"chkconfig_
prog_path
"
,
"/sbin/chkconfig"
,
str
)
(
SERVICE_NAME
,
"initd_dir"
,
"/etc/rc.d/init.d"
,
str
),
(
SERVICE_NAME
,
"chkconfig_
bin
"
,
"/sbin/chkconfig"
,
str
)
]
...
...
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