Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
4f249902
Commit
4f249902
authored
Feb 17, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Taught service how to use --check mode
parent
b3eb1f32
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
6 deletions
+34
-6
library/service
+34
-6
No files found.
library/service
View file @
4f249902
...
...
@@ -117,8 +117,8 @@ class Service(object):
# select whether we dump additional debug info through syslog
self
.
syslogging
=
False
# ===========================================
# Platform specific methods (must be replaced by subclass).
# ===========================================
# Platform specific methods (must be replaced by subclass).
def
get_service_tools
(
self
):
self
.
module
.
fail_json
(
msg
=
"get_service_tools not implemented on target platform"
)
...
...
@@ -132,8 +132,8 @@ class Service(object):
def
service_control
(
self
):
self
.
module
.
fail_json
(
msg
=
"service_control not implemented on target platform"
)
# ===========================================
# Generic methods that should be used on all platforms.
# ===========================================
# Generic methods that should be used on all platforms.
def
execute_command
(
self
,
cmd
,
daemonize
=
False
):
if
self
.
syslogging
:
...
...
@@ -245,8 +245,11 @@ class Service(object):
self
.
changed
=
True
elif
self
.
state
==
"restarted"
:
self
.
changed
=
True
if
self
.
module
.
check_mode
and
self
.
changed
:
self
.
module
.
exit_json
(
changed
=
True
,
msg
=
'service state changed'
)
def
modify_service_state
(
self
):
# Only do something if state will change
if
self
.
changed
:
# Control service
...
...
@@ -259,6 +262,9 @@ class Service(object):
elif
self
.
state
==
'restarted'
:
self
.
action
=
"restart"
if
self
.
module
.
check_mode
:
self
.
module
.
exit_json
(
changed
=
True
,
msg
=
'changing service state'
)
return
self
.
service_control
()
else
:
...
...
@@ -305,6 +311,10 @@ class Service(object):
changed
=
True
if
changed
is
True
:
if
self
.
module
.
check_mode
:
self
.
module
.
exit_json
(
changed
=
True
,
msg
=
"changing service enablement"
)
# Create a temporary file next to the current rc.conf (so we stay on the same filesystem).
# This way the replacement operation is atomic.
rcconf_dir
=
os
.
path
.
dirname
(
self
.
rcconf_file
)
...
...
@@ -442,7 +452,15 @@ class LinuxService(Service):
else
:
args
=
(
self
.
enable_cmd
,
self
.
name
,
on_off
)
if
self
.
enable
is
not
None
:
# FIXME: we need this function to detect whether to run the command
# so we need something to get the service enablement state here.
changed
=
True
if
self
.
module
.
check_mode
and
changed
:
self
.
module
.
exit_json
(
changed
=
True
,
msg
=
"editing service enablement"
)
if
self
.
enable
is
not
None
and
changed
:
return
self
.
execute_command
(
"
%
s
%
s
%
s"
%
args
)
def
service_control
(
self
):
...
...
@@ -508,9 +526,14 @@ class FreeBsdService(Service):
self
.
rcconf_key
=
"
%
s_enable"
%
self
.
name
# FIXME: detect the enablement state rather than just running the command
if
self
.
module
.
check_mode
:
self
.
module
.
exit_json
(
changed
=
True
,
msg
=
"editing service enablement"
)
return
self
.
service_enable_rcconf
()
def
service_control
(
self
):
if
self
.
action
is
"start"
:
self
.
action
=
"onestart"
if
self
.
action
is
"stop"
:
...
...
@@ -586,6 +609,10 @@ class NetBsdService(Service):
else
:
self
.
rcconf_value
=
"NO"
# FIXME: need to decide whether to run enablement command or not
if
self
.
module
.
check_mode
:
self
.
module
.
exit_json
(
changed
=
True
,
msg
=
"editing service enablement"
)
rcfiles
=
[
'/etc/rc.conf'
]
# Overkill?
for
rcfile
in
rcfiles
:
if
os
.
path
.
isfile
(
rcfile
):
...
...
@@ -624,7 +651,8 @@ def main():
pattern
=
dict
(
required
=
False
,
default
=
None
),
enabled
=
dict
(
choices
=
BOOLEANS
),
arguments
=
dict
(
aliases
=
[
'args'
],
default
=
''
),
)
),
supports_check_mode
=
True
)
service
=
Service
(
module
)
...
...
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