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
bc571ccb
Commit
bc571ccb
authored
Aug 17, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #902 from sfromm/issue719
Add pattern option to service module
parents
2b51cf04
18f0302d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
3 deletions
+33
-3
library/service
+33
-3
No files found.
library/service
View file @
bc571ccb
...
...
@@ -18,9 +18,12 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import
platform
SERVICE
=
None
CHKCONFIG
=
None
INITCTL
=
None
PS_OPTIONS
=
'auxww'
def
_find_binaries
(
m
):
# list of possible paths for service/chkconfig binaries
...
...
@@ -56,14 +59,33 @@ def _find_binaries(m):
else
:
INITCTL
=
None
def
_get_service_status
(
name
):
def
_get_service_status
(
name
,
pattern
):
rc
,
status_stdout
,
status_stderr
=
_run
(
"
%
s
%
s status"
%
(
SERVICE
,
name
))
# set the running state to None because we don't know it yet
running
=
None
# If pattern is provided, search for that
# before checking initctl, service output, and other tricks
if
pattern
is
not
None
:
psbin
=
'/bin/ps'
if
not
os
.
path
.
exists
(
psbin
):
if
os
.
path
.
exists
(
'/usr/bin/ps'
):
psbin
=
'/usr/bin/ps'
else
:
psbin
=
None
if
psbin
is
not
None
:
(
rc
,
psout
,
pserr
)
=
_run
(
'
%
s
%
s'
%
(
psbin
,
PS_OPTIONS
))
# If rc is 0, set running as appropriate
# If ps command fails, fall back to other means.
if
rc
==
0
:
if
pattern
in
psout
:
running
=
True
else
:
running
=
False
# Check if we got upstart on the system and then the job state
if
INITCTL
!=
None
:
if
INITCTL
!=
None
and
running
is
None
:
# check the job status by upstart response
initctl_rc
,
initctl_status_stdout
,
initctl_status_stderr
=
_run
(
"
%
s status
%
s"
%
(
INITCTL
,
name
))
if
initctl_status_stdout
.
find
(
"stop/waiting"
)
!=
-
1
:
...
...
@@ -134,21 +156,29 @@ def main():
argument_spec
=
dict
(
name
=
dict
(
required
=
True
),
state
=
dict
(
choices
=
[
'running'
,
'started'
,
'stopped'
,
'restarted'
,
'reloaded'
]),
pattern
=
dict
(
required
=
False
,
default
=
None
),
enabled
=
dict
(
choices
=
BOOLEANS
)
)
)
name
=
module
.
params
[
'name'
]
state
=
module
.
params
[
'state'
]
pattern
=
module
.
params
[
'pattern'
]
enable
=
module
.
boolean
(
module
.
params
.
get
(
'enabled'
,
None
))
# Set PS options here if 'ps auxww' will not work on
# target platform
if
platform
.
system
()
==
'SunOS'
:
global
PS_OPTIONS
PS_OPTIONS
=
'-ef'
# ===========================================
# find binaries locations on minion
_find_binaries
(
module
)
# ===========================================
# get service status
running
=
_get_service_status
(
name
)
running
=
_get_service_status
(
name
,
pattern
)
# ===========================================
# Some common variables
...
...
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