2013-11-27 07:53:57 -06:00
|
|
|
#!/usr/bin/python2
|
2010-12-04 14:42:14 -06:00
|
|
|
# Authors: Simo Sorce <ssorce@redhat.com>
|
2008-02-28 10:37:06 -06:00
|
|
|
#
|
2010-12-04 14:42:14 -06:00
|
|
|
# Copyright (C) 2008-2010 Red Hat
|
2008-02-28 10:37:06 -06:00
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2008-02-28 10:37:06 -06:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-02-28 10:37:06 -06:00
|
|
|
#
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2015-08-12 06:44:11 -05:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2010-12-04 14:42:14 -06:00
|
|
|
import sys
|
2013-01-30 06:51:46 -06:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
|
|
import ldapurl
|
|
|
|
|
|
|
|
from ipaserver.install import service, installutils
|
2015-04-27 07:42:31 -05:00
|
|
|
from ipaserver.install.dsinstance import config_dirname
|
2013-01-30 06:51:46 -06:00
|
|
|
from ipaserver.install.installutils import is_ipa_configured, ScriptError
|
|
|
|
from ipalib import api, errors
|
2013-01-31 05:59:35 -06:00
|
|
|
from ipapython.ipaldap import IPAdmin
|
2013-01-30 06:51:46 -06:00
|
|
|
from ipapython.ipautil import wait_for_open_ports, wait_for_open_socket
|
2015-12-16 09:06:03 -06:00
|
|
|
from ipapython import config
|
2014-05-29 03:51:08 -05:00
|
|
|
from ipaplatform.tasks import tasks
|
2013-01-30 06:51:46 -06:00
|
|
|
from ipapython.dn import DN
|
2014-05-29 03:37:18 -05:00
|
|
|
from ipaplatform import services
|
2014-05-29 03:44:57 -05:00
|
|
|
from ipaplatform.paths import paths
|
2011-01-19 14:17:25 -06:00
|
|
|
|
2016-04-29 10:13:55 -05:00
|
|
|
|
|
|
|
MSG_HINT_IGNORE_SERVICE_FAILURE = (
|
|
|
|
"Hint: You can use --ignore-service-failure option for forced start in "
|
|
|
|
"case that a non-critical service failed"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2012-05-31 07:34:09 -05:00
|
|
|
class IpactlError(ScriptError):
|
|
|
|
pass
|
2011-03-07 10:35:17 -06:00
|
|
|
|
|
|
|
def check_IPA_configuration():
|
2011-08-29 10:16:52 -05:00
|
|
|
if not is_ipa_configured():
|
2011-03-07 10:35:17 -06:00
|
|
|
# LSB status code 6: program is not configured
|
|
|
|
raise IpactlError("IPA is not configured " +
|
|
|
|
"(see man pages of ipa-server-install for help)", 6)
|
|
|
|
|
2015-08-26 08:10:16 -05:00
|
|
|
def deduplicate(lst):
|
2015-08-27 00:34:02 -05:00
|
|
|
"""Remove duplicates and preserve order.
|
|
|
|
Returns copy of list with preserved order and removed duplicates.
|
|
|
|
"""
|
2015-08-26 08:10:16 -05:00
|
|
|
new_lst = []
|
|
|
|
s = set(lst)
|
|
|
|
for i in lst:
|
|
|
|
if i in s:
|
|
|
|
s.remove(i)
|
|
|
|
new_lst.append(i)
|
|
|
|
|
|
|
|
return new_lst
|
|
|
|
|
2011-08-19 16:02:28 -05:00
|
|
|
def is_dirsrv_debugging_enabled():
|
|
|
|
"""
|
2012-11-15 08:38:24 -06:00
|
|
|
Check the 389-ds instance to see if debugging is enabled.
|
|
|
|
If so we suppress that in our output.
|
2011-08-19 16:02:28 -05:00
|
|
|
|
|
|
|
returns True or False
|
|
|
|
"""
|
|
|
|
debugging = False
|
2015-04-27 07:42:31 -05:00
|
|
|
serverid = installutils.realm_to_serverid(api.env.realm)
|
2012-09-19 22:35:42 -05:00
|
|
|
dselist = [config_dirname(serverid)]
|
|
|
|
for dse in dselist:
|
2011-08-19 16:02:28 -05:00
|
|
|
try:
|
|
|
|
fd = open(dse + 'dse.ldif', 'r')
|
|
|
|
except IOError:
|
|
|
|
continue
|
|
|
|
lines = fd.readlines()
|
|
|
|
fd.close()
|
|
|
|
for line in lines:
|
|
|
|
if line.lower().startswith('nsslapd-errorlog-level'):
|
|
|
|
(option, value) = line.split(':')
|
|
|
|
if int(value) > 0:
|
|
|
|
debugging = True
|
|
|
|
|
|
|
|
return debugging
|
|
|
|
|
|
|
|
def get_capture_output(service, debug):
|
|
|
|
"""
|
|
|
|
We want to display any output of a start/stop command with the
|
|
|
|
exception of 389-ds when debugging is enabled because it outputs
|
|
|
|
tons and tons of information.
|
|
|
|
"""
|
|
|
|
if service == 'dirsrv' and not debug and is_dirsrv_debugging_enabled():
|
2015-08-12 06:44:11 -05:00
|
|
|
print(' debugging enabled, suppressing output.')
|
2011-08-19 16:02:28 -05:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2010-12-04 14:42:14 -06:00
|
|
|
def parse_options():
|
|
|
|
usage = "%prog start|stop|restart|status\n"
|
|
|
|
parser = config.IPAOptionParser(usage=usage,
|
|
|
|
formatter=config.IPAFormatter())
|
|
|
|
|
|
|
|
parser.add_option("-d", "--debug", action="store_true", dest="debug",
|
|
|
|
help="Display debugging information")
|
2014-02-20 08:34:05 -06:00
|
|
|
parser.add_option("-f", "--force", action="store_true", dest="force",
|
2015-04-10 08:42:58 -05:00
|
|
|
help="Force IPA to start. Combine options "
|
|
|
|
"--skip-version-check and --ignore-service-failures")
|
|
|
|
parser.add_option("--ignore-service-failures", action="store_true",
|
|
|
|
dest="ignore_service_failures",
|
|
|
|
help="If any service start fails, do not rollback the "
|
|
|
|
"services, continue with the operation")
|
|
|
|
parser.add_option("--skip-version-check", action="store_true",
|
|
|
|
dest="skip_version_check", default=False,
|
|
|
|
help="skip version check")
|
2010-12-04 14:42:14 -06:00
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
safe_options = parser.get_safe_opts(options)
|
|
|
|
|
2015-04-10 08:42:58 -05:00
|
|
|
if options.force:
|
|
|
|
options.ignore_service_failures = True
|
|
|
|
options.skip_version_check = True
|
|
|
|
|
2010-12-04 14:42:14 -06:00
|
|
|
return safe_options, options, args
|
|
|
|
|
|
|
|
def emit_err(err):
|
2011-02-10 08:42:36 -06:00
|
|
|
sys.stderr.write(err + '\n')
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2015-04-10 08:42:58 -05:00
|
|
|
|
|
|
|
def version_check():
|
|
|
|
try:
|
|
|
|
installutils.check_version()
|
|
|
|
except (installutils.UpgradeMissingVersionError,
|
|
|
|
installutils.UpgradeDataOlderVersionError):
|
|
|
|
emit_err("Upgrade required: please run ipa-server-upgrade command")
|
|
|
|
raise IpactlError("Aborting ipactl")
|
|
|
|
except installutils.UpgradeVersionError as e:
|
|
|
|
emit_err("IPA version error: %s" % e)
|
|
|
|
raise IpactlError("Aborting ipactl")
|
|
|
|
|
|
|
|
|
2012-05-24 10:23:36 -05:00
|
|
|
def get_config(dirsrv):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
base = DN(('cn', api.env.host), ('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'), api.env.basedn)
|
2010-12-04 14:42:14 -06:00
|
|
|
srcfilter = '(ipaConfigString=enabledService)'
|
|
|
|
attrs = ['cn', 'ipaConfigString']
|
2012-05-24 10:23:36 -05:00
|
|
|
if not dirsrv.is_running():
|
|
|
|
raise IpactlError("Failed to get list of services to probe status:\n" +
|
|
|
|
"Directory Server is stopped", 3)
|
2010-12-04 14:42:14 -06:00
|
|
|
|
|
|
|
try:
|
2012-05-24 10:23:36 -05:00
|
|
|
# The start/restart functions already wait for the server to be
|
|
|
|
# started. What we are doing with this wait is really checking to see
|
|
|
|
# if the server is listening at all.
|
2011-10-10 07:25:15 -05:00
|
|
|
lurl = ldapurl.LDAPUrl(api.env.ldap_uri)
|
|
|
|
if lurl.urlscheme == 'ldapi':
|
2012-05-24 10:23:36 -05:00
|
|
|
wait_for_open_socket(lurl.hostport, timeout=api.env.startup_timeout)
|
2011-10-10 07:25:15 -05:00
|
|
|
else:
|
2013-01-30 06:51:46 -06:00
|
|
|
(host, port) = lurl.hostport.split(':')
|
2012-05-24 10:23:36 -05:00
|
|
|
wait_for_open_ports(host, [int(port)], timeout=api.env.startup_timeout)
|
2013-01-30 06:51:46 -06:00
|
|
|
con = IPAdmin(ldap_uri=api.env.ldap_uri)
|
|
|
|
con.do_external_bind()
|
2016-03-18 03:49:41 -05:00
|
|
|
res = con.get_entries(
|
|
|
|
base,
|
2013-01-30 06:51:46 -06:00
|
|
|
filter=srcfilter,
|
|
|
|
attrs_list=attrs,
|
|
|
|
scope=con.SCOPE_SUBTREE,
|
|
|
|
time_limit=10)
|
|
|
|
except errors.NetworkError:
|
2011-03-07 10:35:17 -06:00
|
|
|
# LSB status code 3: program is not running
|
|
|
|
raise IpactlError("Failed to get list of services to probe status:\n" +
|
|
|
|
"Directory Server is stopped", 3)
|
2013-01-30 06:51:46 -06:00
|
|
|
except errors.NotFound:
|
2011-08-03 05:44:46 -05:00
|
|
|
masters_list = []
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
dn = DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'), api.env.basedn)
|
2011-08-03 05:44:46 -05:00
|
|
|
attrs = ['cn']
|
|
|
|
try:
|
2013-01-30 06:51:46 -06:00
|
|
|
entries = con.get_entries(dn, con.SCOPE_ONELEVEL, attrs_list=attrs)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2011-08-03 05:44:46 -05:00
|
|
|
masters_list.append("No master found because of error: %s" % str(e))
|
|
|
|
else:
|
2013-10-31 11:54:49 -05:00
|
|
|
for master_entry in entries:
|
2013-09-10 05:20:24 -05:00
|
|
|
masters_list.append(master_entry.single_value['cn'])
|
2011-08-03 05:44:46 -05:00
|
|
|
|
|
|
|
masters = "\n".join(masters_list)
|
|
|
|
|
|
|
|
raise IpactlError("Failed to get list of services to probe status!\n"
|
|
|
|
"Configured hostname '%s' does not match any master server in LDAP:\n%s"
|
|
|
|
% (api.env.host, masters))
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2011-03-07 10:35:17 -06:00
|
|
|
raise IpactlError("Unknown error when retrieving list of services from LDAP: " + str(e))
|
2010-12-04 14:42:14 -06:00
|
|
|
|
|
|
|
svc_list = []
|
|
|
|
|
|
|
|
for entry in res:
|
2013-09-10 05:20:24 -05:00
|
|
|
name = entry.single_value['cn']
|
2013-01-30 06:51:46 -06:00
|
|
|
for p in entry['ipaConfigString']:
|
2010-12-04 14:42:14 -06:00
|
|
|
if p.startswith('startOrder '):
|
2014-10-08 09:40:53 -05:00
|
|
|
try:
|
|
|
|
order = int(p.split()[1])
|
|
|
|
except ValueError:
|
|
|
|
raise IpactlError("Expected order as integer in: %s:%s" % (
|
|
|
|
name, p))
|
2012-10-31 13:10:41 -05:00
|
|
|
svc_list.append([order, name])
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2012-10-31 13:10:41 -05:00
|
|
|
ordered_list = []
|
|
|
|
for (order, svc) in sorted(svc_list):
|
|
|
|
if svc in service.SERVICE_LIST:
|
|
|
|
ordered_list.append(service.SERVICE_LIST[svc][0])
|
|
|
|
return ordered_list
|
|
|
|
|
|
|
|
def get_config_from_file():
|
|
|
|
|
|
|
|
svc_list = []
|
|
|
|
|
|
|
|
try:
|
2014-05-29 03:18:21 -05:00
|
|
|
f = open(tasks.get_svc_list_file(), 'r')
|
2012-10-31 13:10:41 -05:00
|
|
|
svc_list = json.load(f)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-10-31 13:10:41 -05:00
|
|
|
raise IpactlError("Unknown error when retrieving list of services from file: " + str(e))
|
|
|
|
|
|
|
|
# the framework can start/stop a number of related services we are not
|
|
|
|
# authoritative for, so filter the list through SERVICES_LIST and order it
|
|
|
|
# accordingly too.
|
|
|
|
|
|
|
|
def_svc_list = []
|
|
|
|
for svc in service.SERVICE_LIST:
|
|
|
|
s = service.SERVICE_LIST[svc]
|
|
|
|
def_svc_list.append([s[1], s[0]])
|
|
|
|
|
|
|
|
ordered_list = []
|
|
|
|
for (order, svc) in sorted(def_svc_list):
|
|
|
|
if svc in svc_list:
|
|
|
|
ordered_list.append(svc)
|
|
|
|
|
|
|
|
return ordered_list
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2014-02-20 08:34:05 -06:00
|
|
|
|
|
|
|
def stop_services(svc_list):
|
|
|
|
for svc in svc_list:
|
2014-05-29 03:37:18 -05:00
|
|
|
svc_off = services.service(svc)
|
2014-02-20 08:34:05 -06:00
|
|
|
try:
|
|
|
|
svc_off.stop(capture_output=False)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def stop_dirsrv(dirsrv):
|
|
|
|
try:
|
|
|
|
dirsrv.stop(capture_output=False)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2011-08-19 16:02:28 -05:00
|
|
|
def ipa_start(options):
|
2012-10-31 13:10:41 -05:00
|
|
|
|
2015-04-10 08:42:58 -05:00
|
|
|
if not options.skip_version_check:
|
|
|
|
version_check()
|
|
|
|
else:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Skipping version check")
|
2015-04-10 08:42:58 -05:00
|
|
|
|
2014-05-29 03:18:21 -05:00
|
|
|
if os.path.isfile(tasks.get_svc_list_file()):
|
2012-10-31 13:10:41 -05:00
|
|
|
emit_err("Existing service file detected!")
|
|
|
|
emit_err("Assuming stale, cleaning and proceeding")
|
|
|
|
# remove file with list of started services
|
|
|
|
# This is ok as systemd will just skip services
|
|
|
|
# that are already running and just return, so that the
|
|
|
|
# stop() method of the base class will simply fill in the
|
|
|
|
# service file again
|
2014-05-29 03:44:57 -05:00
|
|
|
os.unlink(paths.SVC_LIST_FILE)
|
2012-10-31 13:10:41 -05:00
|
|
|
|
2014-05-29 03:37:18 -05:00
|
|
|
dirsrv = services.knownservices.dirsrv
|
2010-12-04 14:42:14 -06:00
|
|
|
try:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Starting Directory Service")
|
2011-09-12 16:11:54 -05:00
|
|
|
dirsrv.start(capture_output=get_capture_output('dirsrv', options.debug))
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2011-03-07 10:35:17 -06:00
|
|
|
raise IpactlError("Failed to start Directory Service: " + str(e))
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2012-10-31 13:10:41 -05:00
|
|
|
ldap_list = []
|
2010-12-10 16:40:37 -06:00
|
|
|
try:
|
2012-05-24 10:23:36 -05:00
|
|
|
svc_list = get_config(dirsrv)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2014-05-06 02:52:21 -05:00
|
|
|
emit_err("Failed to read data from service file: " + str(e))
|
2010-12-10 16:40:37 -06:00
|
|
|
emit_err("Shutting down")
|
2014-02-20 08:34:05 -06:00
|
|
|
|
2015-04-10 08:42:58 -05:00
|
|
|
if not options.ignore_service_failures:
|
2014-02-20 08:34:05 -06:00
|
|
|
stop_dirsrv(dirsrv)
|
|
|
|
|
2011-03-07 10:35:17 -06:00
|
|
|
if isinstance(e, IpactlError):
|
|
|
|
# do not display any other error message
|
2016-02-25 06:46:33 -06:00
|
|
|
raise IpactlError(rval=e.rval) # pylint: disable=no-member
|
2011-03-07 10:35:17 -06:00
|
|
|
else:
|
2012-08-20 15:47:52 -05:00
|
|
|
raise IpactlError()
|
2010-12-10 16:40:37 -06:00
|
|
|
|
|
|
|
if len(svc_list) == 0:
|
2012-10-31 13:10:41 -05:00
|
|
|
# no service to start
|
2010-12-10 16:40:37 -06:00
|
|
|
return
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2015-08-26 08:10:16 -05:00
|
|
|
svc_list = deduplicate(svc_list)
|
2012-10-31 13:10:41 -05:00
|
|
|
for svc in svc_list:
|
2014-05-29 03:37:18 -05:00
|
|
|
svchandle = services.service(svc)
|
2010-12-04 14:42:14 -06:00
|
|
|
try:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Starting %s Service" % svc)
|
2012-10-31 13:10:41 -05:00
|
|
|
svchandle.start(capture_output=get_capture_output(svc, options.debug))
|
2014-02-20 08:34:05 -06:00
|
|
|
except Exception:
|
2010-12-04 14:42:14 -06:00
|
|
|
emit_err("Failed to start %s Service" % svc)
|
2015-04-10 08:42:58 -05:00
|
|
|
# if ignore_service_failures is specified, skip rollback and
|
|
|
|
# continue with the next service
|
|
|
|
if options.ignore_service_failures:
|
2014-02-20 08:34:05 -06:00
|
|
|
emit_err("Forced start, ignoring %s Service, continuing normal operation" % svc)
|
|
|
|
continue
|
|
|
|
|
2010-12-04 14:42:14 -06:00
|
|
|
emit_err("Shutting down")
|
2014-02-20 08:34:05 -06:00
|
|
|
stop_services(svc_list)
|
|
|
|
stop_dirsrv(dirsrv)
|
|
|
|
|
2016-04-29 10:13:55 -05:00
|
|
|
emit_err(MSG_HINT_IGNORE_SERVICE_FAILURE)
|
2011-03-07 10:35:17 -06:00
|
|
|
raise IpactlError("Aborting ipactl")
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2011-08-19 16:02:28 -05:00
|
|
|
def ipa_stop(options):
|
2014-05-29 03:37:18 -05:00
|
|
|
dirsrv = services.knownservices.dirsrv
|
2010-12-10 16:40:37 -06:00
|
|
|
try:
|
2012-10-31 13:10:41 -05:00
|
|
|
svc_list = get_config_from_file()
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-10-31 13:10:41 -05:00
|
|
|
# Issue reading the file ? Let's try to get data from LDAP as a
|
|
|
|
# fallback
|
2010-12-10 16:40:37 -06:00
|
|
|
try:
|
2011-09-12 16:11:54 -05:00
|
|
|
dirsrv.start(capture_output=False)
|
2012-05-24 10:23:36 -05:00
|
|
|
svc_list = get_config(dirsrv)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2011-03-07 10:35:17 -06:00
|
|
|
emit_err("Failed to read data from Directory Service: " + str(e))
|
2010-12-10 16:40:37 -06:00
|
|
|
emit_err("Shutting down")
|
2011-03-07 10:35:17 -06:00
|
|
|
try:
|
|
|
|
# just try to stop it, do not read a result
|
2011-09-12 16:11:54 -05:00
|
|
|
dirsrv.stop()
|
2011-03-07 10:35:17 -06:00
|
|
|
finally:
|
2012-08-20 15:47:52 -05:00
|
|
|
raise IpactlError()
|
2010-12-10 16:40:37 -06:00
|
|
|
|
2015-08-26 08:10:16 -05:00
|
|
|
svc_list = deduplicate(svc_list)
|
2012-10-31 13:10:41 -05:00
|
|
|
for svc in reversed(svc_list):
|
2014-05-29 03:37:18 -05:00
|
|
|
svchandle = services.service(svc)
|
2010-12-04 14:42:14 -06:00
|
|
|
try:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Stopping %s Service" % svc)
|
2011-09-12 16:11:54 -05:00
|
|
|
svchandle.stop(capture_output=False)
|
2016-03-11 12:51:07 -06:00
|
|
|
except Exception:
|
2010-12-04 14:42:14 -06:00
|
|
|
emit_err("Failed to stop %s Service" % svc)
|
|
|
|
|
2014-11-04 02:22:59 -06:00
|
|
|
try:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Stopping Directory Service")
|
2014-11-04 02:22:59 -06:00
|
|
|
dirsrv.stop(capture_output=False)
|
2016-03-11 12:51:07 -06:00
|
|
|
except Exception:
|
2014-11-04 02:22:59 -06:00
|
|
|
raise IpactlError("Failed to stop Directory Service")
|
|
|
|
|
2012-10-31 13:10:41 -05:00
|
|
|
# remove file with list of started services
|
2013-04-26 07:46:17 -05:00
|
|
|
try:
|
2014-05-29 03:44:57 -05:00
|
|
|
os.unlink(paths.SVC_LIST_FILE)
|
2013-04-26 07:46:17 -05:00
|
|
|
except OSError:
|
|
|
|
pass
|
2012-10-31 13:10:41 -05:00
|
|
|
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2011-08-19 16:02:28 -05:00
|
|
|
def ipa_restart(options):
|
2015-04-10 08:42:58 -05:00
|
|
|
if not options.skip_version_check:
|
|
|
|
version_check()
|
|
|
|
else:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Skipping version check")
|
2015-04-10 08:42:58 -05:00
|
|
|
|
2014-05-29 03:37:18 -05:00
|
|
|
dirsrv = services.knownservices.dirsrv
|
2012-10-31 13:10:41 -05:00
|
|
|
new_svc_list = []
|
2014-02-19 09:41:39 -06:00
|
|
|
dirsrv_restart = True
|
|
|
|
if not dirsrv.is_running():
|
|
|
|
try:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Starting Directory Service")
|
2014-02-19 09:41:39 -06:00
|
|
|
dirsrv.start(capture_output=get_capture_output('dirsrv', options.debug))
|
|
|
|
dirsrv_restart = False
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2014-02-19 09:41:39 -06:00
|
|
|
raise IpactlError("Failed to start Directory Service: " + str(e))
|
|
|
|
|
2010-12-04 14:42:14 -06:00
|
|
|
try:
|
2012-10-31 13:10:41 -05:00
|
|
|
new_svc_list = get_config(dirsrv)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2011-03-07 10:35:17 -06:00
|
|
|
emit_err("Failed to read data from Directory Service: " + str(e))
|
2010-12-10 16:40:37 -06:00
|
|
|
emit_err("Shutting down")
|
2011-03-07 10:35:17 -06:00
|
|
|
try:
|
2011-09-12 16:11:54 -05:00
|
|
|
dirsrv.stop(capture_output=False)
|
2016-03-11 12:51:07 -06:00
|
|
|
except Exception:
|
2011-03-07 10:35:17 -06:00
|
|
|
pass
|
|
|
|
if isinstance(e, IpactlError):
|
|
|
|
# do not display any other error message
|
2016-02-25 06:46:33 -06:00
|
|
|
raise IpactlError(rval=e.rval) # pylint: disable=no-member
|
2011-03-07 10:35:17 -06:00
|
|
|
else:
|
2012-08-20 15:47:52 -05:00
|
|
|
raise IpactlError()
|
2010-12-10 16:40:37 -06:00
|
|
|
|
2012-10-31 13:10:41 -05:00
|
|
|
old_svc_list = []
|
|
|
|
try:
|
|
|
|
old_svc_list = get_config_from_file()
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-10-31 13:10:41 -05:00
|
|
|
emit_err("Failed to get service list from file: " + str(e))
|
|
|
|
# fallback to what's in LDAP
|
|
|
|
old_svc_list = new_svc_list
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2012-10-31 13:10:41 -05:00
|
|
|
# match service to start/stop
|
|
|
|
svc_list = []
|
|
|
|
for s in new_svc_list:
|
|
|
|
if s in old_svc_list:
|
|
|
|
svc_list.append(s)
|
|
|
|
|
|
|
|
#remove commons
|
|
|
|
for s in svc_list:
|
|
|
|
if s in old_svc_list:
|
|
|
|
old_svc_list.remove(s)
|
|
|
|
for s in svc_list:
|
|
|
|
if s in new_svc_list:
|
|
|
|
new_svc_list.remove(s)
|
|
|
|
|
|
|
|
if len(old_svc_list) != 0:
|
|
|
|
# we need to definitely stop some services
|
2015-08-26 08:10:16 -05:00
|
|
|
old_svc_list = deduplicate(old_svc_list)
|
2012-10-31 13:10:41 -05:00
|
|
|
for svc in reversed(old_svc_list):
|
2014-05-29 03:37:18 -05:00
|
|
|
svchandle = services.service(svc)
|
2012-10-31 13:10:41 -05:00
|
|
|
try:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Stopping %s Service" % svc)
|
2012-10-31 13:10:41 -05:00
|
|
|
svchandle.stop(capture_output=False)
|
2016-03-11 12:51:07 -06:00
|
|
|
except Exception:
|
2012-10-31 13:10:41 -05:00
|
|
|
emit_err("Failed to stop %s Service" % svc)
|
|
|
|
|
|
|
|
try:
|
2014-02-19 09:41:39 -06:00
|
|
|
if dirsrv_restart:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Restarting Directory Service")
|
2014-02-19 09:41:39 -06:00
|
|
|
dirsrv.restart(capture_output=get_capture_output('dirsrv', options.debug))
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-10-31 13:10:41 -05:00
|
|
|
emit_err("Failed to restart Directory Service: " + str(e))
|
|
|
|
emit_err("Shutting down")
|
2014-02-20 08:34:05 -06:00
|
|
|
|
2015-04-10 08:42:58 -05:00
|
|
|
if not options.ignore_service_failures:
|
2014-02-20 08:34:05 -06:00
|
|
|
stop_services(reversed(svc_list))
|
|
|
|
stop_dirsrv(dirsrv)
|
|
|
|
|
2012-10-31 13:10:41 -05:00
|
|
|
raise IpactlError("Aborting ipactl")
|
|
|
|
|
|
|
|
if len(svc_list) != 0:
|
|
|
|
# there are services to restart
|
2015-08-26 08:10:16 -05:00
|
|
|
svc_list = deduplicate(svc_list)
|
2012-10-31 13:10:41 -05:00
|
|
|
for svc in svc_list:
|
2014-05-29 03:37:18 -05:00
|
|
|
svchandle = services.service(svc)
|
2012-10-31 13:10:41 -05:00
|
|
|
try:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Restarting %s Service" % svc)
|
2012-10-31 13:10:41 -05:00
|
|
|
svchandle.restart(capture_output=get_capture_output(svc, options.debug))
|
2014-02-20 08:34:05 -06:00
|
|
|
except Exception:
|
2012-10-31 13:10:41 -05:00
|
|
|
emit_err("Failed to restart %s Service" % svc)
|
2015-04-10 08:42:58 -05:00
|
|
|
# if ignore_service_failures is specified,
|
|
|
|
# skip rollback and continue with the next service
|
|
|
|
if options.ignore_service_failures:
|
2014-02-20 08:34:05 -06:00
|
|
|
emit_err("Forced restart, ignoring %s Service, continuing normal operation" % svc)
|
|
|
|
continue
|
|
|
|
|
2012-10-31 13:10:41 -05:00
|
|
|
emit_err("Shutting down")
|
2014-02-20 08:34:05 -06:00
|
|
|
stop_services(svc_list)
|
|
|
|
stop_dirsrv(dirsrv)
|
|
|
|
|
2016-04-29 10:13:55 -05:00
|
|
|
emit_err(MSG_HINT_IGNORE_SERVICE_FAILURE)
|
2012-10-31 13:10:41 -05:00
|
|
|
raise IpactlError("Aborting ipactl")
|
|
|
|
|
|
|
|
if len(new_svc_list) != 0:
|
|
|
|
# we still need to start some services
|
2015-08-26 08:10:16 -05:00
|
|
|
new_svc_list = deduplicate(new_svc_list)
|
2012-10-31 13:10:41 -05:00
|
|
|
for svc in new_svc_list:
|
2014-05-29 03:37:18 -05:00
|
|
|
svchandle = services.service(svc)
|
2010-12-04 14:42:14 -06:00
|
|
|
try:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Starting %s Service" % svc)
|
2012-10-31 13:10:41 -05:00
|
|
|
svchandle.start(capture_output=get_capture_output(svc, options.debug))
|
2014-02-20 08:34:05 -06:00
|
|
|
except Exception:
|
2012-10-31 13:10:41 -05:00
|
|
|
emit_err("Failed to start %s Service" % svc)
|
2015-04-10 08:42:58 -05:00
|
|
|
# if ignore_service_failures is specified, skip rollback and
|
|
|
|
# continue with the next service
|
|
|
|
if options.ignore_service_failures:
|
2014-02-20 08:34:05 -06:00
|
|
|
emit_err("Forced start, ignoring %s Service, continuing normal operation" % svc)
|
|
|
|
continue
|
|
|
|
|
2012-10-31 13:10:41 -05:00
|
|
|
emit_err("Shutting down")
|
2014-02-20 08:34:05 -06:00
|
|
|
stop_services(svc_list)
|
|
|
|
stop_dirsrv(dirsrv)
|
|
|
|
|
2016-04-29 10:13:55 -05:00
|
|
|
emit_err(MSG_HINT_IGNORE_SERVICE_FAILURE)
|
2012-10-31 13:10:41 -05:00
|
|
|
raise IpactlError("Aborting ipactl")
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2011-08-19 16:02:28 -05:00
|
|
|
def ipa_status(options):
|
2012-10-31 13:10:41 -05:00
|
|
|
|
|
|
|
try:
|
2014-05-29 03:37:18 -05:00
|
|
|
dirsrv = services.knownservices.dirsrv
|
2014-02-20 08:34:05 -06:00
|
|
|
if dirsrv.is_running():
|
|
|
|
svc_list = get_config(dirsrv)
|
|
|
|
else:
|
|
|
|
svc_list = get_config_from_file()
|
2015-07-30 09:49:29 -05:00
|
|
|
except IpactlError as e:
|
2014-05-29 03:18:21 -05:00
|
|
|
if os.path.exists(tasks.get_svc_list_file()):
|
2012-12-04 12:55:30 -06:00
|
|
|
raise e
|
|
|
|
else:
|
|
|
|
svc_list = []
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-10-31 13:10:41 -05:00
|
|
|
raise IpactlError("Failed to get list of services to probe status: " + str(e))
|
|
|
|
|
2014-05-29 03:37:18 -05:00
|
|
|
dirsrv = services.knownservices.dirsrv
|
2010-12-04 14:42:14 -06:00
|
|
|
try:
|
2011-09-12 16:11:54 -05:00
|
|
|
if dirsrv.is_running():
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Directory Service: RUNNING")
|
2010-12-04 14:42:14 -06:00
|
|
|
else:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Directory Service: STOPPED")
|
2012-12-04 12:55:30 -06:00
|
|
|
if len(svc_list) == 0:
|
2015-08-12 06:44:11 -05:00
|
|
|
print(("Directory Service must be running in order to " +
|
|
|
|
"obtain status of other services"))
|
2010-12-04 14:42:14 -06:00
|
|
|
except:
|
2011-03-07 10:35:17 -06:00
|
|
|
raise IpactlError("Failed to get Directory Service status")
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2010-12-10 16:40:37 -06:00
|
|
|
if len(svc_list) == 0:
|
|
|
|
return
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2015-08-26 08:10:16 -05:00
|
|
|
svc_list = deduplicate(svc_list)
|
2012-10-31 13:10:41 -05:00
|
|
|
for svc in svc_list:
|
2014-05-29 03:37:18 -05:00
|
|
|
svchandle = services.service(svc)
|
2010-12-04 14:42:14 -06:00
|
|
|
try:
|
2011-09-12 16:11:54 -05:00
|
|
|
if svchandle.is_running():
|
2015-08-12 06:44:11 -05:00
|
|
|
print("%s Service: RUNNING" % svc)
|
2010-12-04 14:42:14 -06:00
|
|
|
else:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("%s Service: STOPPED" % svc)
|
2016-03-11 12:51:07 -06:00
|
|
|
except Exception:
|
2011-03-07 10:35:17 -06:00
|
|
|
emit_err("Failed to get %s Service status" % svc)
|
2010-12-04 14:42:14 -06:00
|
|
|
|
|
|
|
def main():
|
2011-02-15 13:03:00 -06:00
|
|
|
if not os.getegid() == 0:
|
2011-03-07 10:35:17 -06:00
|
|
|
# LSB status code 4: user had insufficient privilege
|
|
|
|
raise IpactlError("You must be root to run ipactl.", 4)
|
2010-12-04 14:42:14 -06:00
|
|
|
|
|
|
|
safe_options, options, args = parse_options()
|
|
|
|
|
|
|
|
if len(args) != 1:
|
2011-03-07 10:35:17 -06:00
|
|
|
# LSB status code 2: invalid or excess argument(s)
|
|
|
|
raise IpactlError("You must specify one action", 2)
|
2010-12-04 14:42:14 -06:00
|
|
|
elif args[0] != "start" and args[0] != "stop" and args[0] != "restart" and args[0] != "status":
|
2011-03-07 10:35:17 -06:00
|
|
|
raise IpactlError("Unrecognized action [" + args[0] + "]", 2)
|
|
|
|
|
|
|
|
# check if IPA is configured at all
|
|
|
|
try:
|
|
|
|
check_IPA_configuration()
|
2015-07-30 09:49:29 -05:00
|
|
|
except IpactlError as e:
|
2011-03-07 10:35:17 -06:00
|
|
|
if args[0].lower() == "status":
|
|
|
|
# Different LSB return code for status command:
|
|
|
|
# 4 - program or service status is unknown
|
|
|
|
# This should differentiate uninstalled IPA from status
|
|
|
|
# code 3 - program is not running
|
|
|
|
e.rval = 4
|
|
|
|
raise e
|
|
|
|
else:
|
|
|
|
raise e
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2012-12-04 12:55:30 -06:00
|
|
|
api.bootstrap(context='ipactl', debug=options.debug)
|
2010-12-04 14:42:14 -06:00
|
|
|
api.finalize()
|
|
|
|
|
2011-06-24 09:56:25 -05:00
|
|
|
if '.' not in api.env.host:
|
2011-08-03 05:44:46 -05:00
|
|
|
raise IpactlError("Invalid hostname '%s' in IPA configuration!\n"
|
|
|
|
"The hostname must be fully-qualified" % api.env.host)
|
2011-06-24 09:56:25 -05:00
|
|
|
|
2010-12-04 14:42:14 -06:00
|
|
|
if args[0].lower() == "start":
|
2011-08-19 16:02:28 -05:00
|
|
|
ipa_start(options)
|
2010-12-04 14:42:14 -06:00
|
|
|
elif args[0].lower() == "stop":
|
2011-08-19 16:02:28 -05:00
|
|
|
ipa_stop(options)
|
2010-12-04 14:42:14 -06:00
|
|
|
elif args[0].lower() == "restart":
|
2011-08-19 16:02:28 -05:00
|
|
|
ipa_restart(options)
|
2010-12-04 14:42:14 -06:00
|
|
|
elif args[0].lower() == "status":
|
2011-08-19 16:02:28 -05:00
|
|
|
ipa_status(options)
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2012-05-31 07:34:09 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
installutils.run_script(main, operation_name='ipactl')
|