2013-11-27 07:53:57 -06:00
|
|
|
#!/usr/bin/python2 -E
|
2012-07-11 14:51:01 -05:00
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@redhat.com>
|
2013-10-16 03:40:31 -05:00
|
|
|
# Jan Cholasta <jcholast@redhat.com>
|
2012-07-11 14:51:01 -05:00
|
|
|
#
|
2013-10-16 03:40:31 -05:00
|
|
|
# Copyright (C) 2013 Red Hat
|
2012-07-11 14:51:01 -05:00
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import syslog
|
2014-01-23 08:33:26 -06:00
|
|
|
import traceback
|
2013-10-16 03:40:31 -05:00
|
|
|
|
2012-07-11 14:51:01 -05:00
|
|
|
from ipalib import api
|
2013-10-16 03:40:31 -05:00
|
|
|
from ipaserver.install import certs, cainstance
|
2014-05-29 03:37:18 -05:00
|
|
|
from ipaplatform import services
|
2013-10-16 03:40:31 -05:00
|
|
|
|
|
|
|
nickname = 'ipaCert'
|
2012-07-11 14:51:01 -05:00
|
|
|
|
2014-01-23 08:33:26 -06:00
|
|
|
def main():
|
|
|
|
api.bootstrap(context='restart')
|
|
|
|
api.finalize()
|
2012-07-11 14:51:01 -05:00
|
|
|
|
2013-10-16 04:04:21 -05:00
|
|
|
ca = cainstance.CAInstance(api.env.realm, certs.NSS_DIR)
|
|
|
|
if ca.is_renewal_master():
|
|
|
|
# Fetch the new certificate
|
|
|
|
db = certs.CertDB(api.env.realm)
|
|
|
|
dercert = db.get_cert_from_db(nickname, pem=False)
|
|
|
|
if not dercert:
|
|
|
|
syslog.syslog(syslog.LOG_ERR, 'No certificate %s found.' % nickname)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Load it into dogtag
|
|
|
|
cainstance.update_people_entry(dercert)
|
2012-10-23 13:07:13 -05:00
|
|
|
|
2014-01-23 08:33:26 -06:00
|
|
|
# Now restart Apache so the new certificate is available
|
2013-10-16 03:40:31 -05:00
|
|
|
syslog.syslog(syslog.LOG_NOTICE, "Restarting httpd")
|
2014-01-23 08:33:26 -06:00
|
|
|
try:
|
2014-05-29 03:37:18 -05:00
|
|
|
services.knownservices.httpd.restart()
|
2014-01-23 08:33:26 -06:00
|
|
|
except Exception, e:
|
2013-10-16 03:40:31 -05:00
|
|
|
syslog.syslog(syslog.LOG_ERR, "Cannot restart httpd: %s" % e)
|
|
|
|
else:
|
|
|
|
syslog.syslog(syslog.LOG_NOTICE, "Restarted httpd")
|
2012-07-11 14:51:01 -05:00
|
|
|
|
|
|
|
try:
|
2014-01-23 08:33:26 -06:00
|
|
|
main()
|
|
|
|
except Exception:
|
|
|
|
syslog.syslog(syslog.LOG_ERR, traceback.format_exc())
|