Add ipa_memcached service

* Adds ipa_memcached SystemV initscript

* Adds ipa_memcached service file and tmpfiles.d/ipa.conf
  to recreate /var/run/ipa_memcached on reboot.

* Adds ipa_memcached config file

* Adds memcacheinstnace.py to manage ipa_memcaced as
  as SimpleService object.

* Updates the IPA service list to include ipa_memcached,
  at service positon 39, httpd is position 40

* Updates the spec file:
  - requires the memcached daemon and python client
  - installs service or initscripts depending on OS
  - installs config file
  - creates /var/run/ipa_memcached directory

* Modifies ipa-server-install to install ipa_memcached
This commit is contained in:
John Dennis 2012-02-06 13:15:06 -05:00 committed by Endi S. Dewata
parent af187713e7
commit d1e0c1b606
8 changed files with 189 additions and 0 deletions

View File

@ -109,6 +109,8 @@ Requires: python-ldap
Requires: python-krbV Requires: python-krbV
Requires: acl Requires: acl
Requires: python-pyasn1 >= 0.0.9a Requires: python-pyasn1 >= 0.0.9a
Requires: memcached
Requires: python-memcached
%if 0%{?fedora} >= 16 %if 0%{?fedora} >= 16
Requires: systemd-units >= 36-3 Requires: systemd-units >= 36-3
Requires(pre): systemd-units Requires(pre): systemd-units
@ -356,12 +358,25 @@ mkdir -p %{buildroot}%{_usr}/share/ipa/html/
/bin/touch %{buildroot}%{_usr}/share/ipa/html/krbrealm.con /bin/touch %{buildroot}%{_usr}/share/ipa/html/krbrealm.con
/bin/touch %{buildroot}%{_usr}/share/ipa/html/preferences.html /bin/touch %{buildroot}%{_usr}/share/ipa/html/preferences.html
mkdir -p %{buildroot}%{_initrddir} mkdir -p %{buildroot}%{_initrddir}
mkdir %{buildroot}%{_sysconfdir}/sysconfig/
install -m 644 init/ipa_memcached.conf %{buildroot}%{_sysconfdir}/sysconfig/ipa_memcached
%if 0%{?fedora} >= 15
mkdir -p %{buildroot}%{_sysconfdir}/tmpfiles.d/
install -m 0644 init/systemd/ipa.conf.tmpfiles %{buildroot}%{_sysconfdir}/tmpfiles.d/ipa.conf
%endif
mkdir -p %{buildroot}%{_localstatedir}/run/
install -d -m 0700 %{buildroot}%{_localstatedir}/run/ipa_memcached/
%if 0%{?fedora} >= 16 %if 0%{?fedora} >= 16
# Default to systemd initscripts for F16 and above # Default to systemd initscripts for F16 and above
mkdir -p %{buildroot}%{_unitdir} mkdir -p %{buildroot}%{_unitdir}
install -m 644 init/systemd/ipa.service %{buildroot}%{_unitdir}/ipa.service install -m 644 init/systemd/ipa.service %{buildroot}%{_unitdir}/ipa.service
install -m 644 init/systemd/ipa_memcached.service %{buildroot}%{_unitdir}/ipa_memcached.service
%else %else
install -m755 init/SystemV/ipa.init %{buildroot}%{_initrddir}/ipa install -m755 init/SystemV/ipa.init %{buildroot}%{_initrddir}/ipa
install -m755 init/SystemV/ipa_memcached.init %{buildroot}%{_initrddir}/ipa_memcached
%endif %endif
%endif %endif
@ -491,12 +506,19 @@ fi
%{_sbindir}/ipa-upgradeconfig %{_sbindir}/ipa-upgradeconfig
%{_sbindir}/ipa-compliance %{_sbindir}/ipa-compliance
%{_sysconfdir}/cron.d/ipa-compliance %{_sysconfdir}/cron.d/ipa-compliance
%config(noreplace) %{_sysconfdir}/sysconfig/ipa_memcached
%dir %attr(0700,apache,apache) %{_localstatedir}/run/ipa_memcached/
%if 0%{?fedora} >= 15
%config %{_sysconfdir}/tmpfiles.d/ipa.conf
%endif
%if 0%{?fedora} >= 16 %if 0%{?fedora} >= 16
# Use systemd scheme # Use systemd scheme
%attr(644,root,root) %{_unitdir}/ipa.service %attr(644,root,root) %{_unitdir}/ipa.service
%attr(644,root,root) %{_unitdir}/ipa_memcached.service
%else %else
# Use SystemV scheme only before F16 # Use SystemV scheme only before F16
%attr(755,root,root) %{_initrddir}/ipa %attr(755,root,root) %{_initrddir}/ipa
%attr(755,root,root) %{_initrddir}/ipa_memcached
%endif %endif
%dir %{python_sitelib}/ipaserver %dir %{python_sitelib}/ipaserver
%{python_sitelib}/ipaserver/* %{python_sitelib}/ipaserver/*

120
init/SystemV/ipa_memcached.init Executable file
View File

@ -0,0 +1,120 @@
#! /bin/sh
#
# chkconfig: - 55 45
# description: The ipa_memcached daemon is a memory cache service for IPA
# processname: memcached
# config: /etc/sysconfig/ipa_memcached
# pidfile: /var/run/ipa_memcached/ipa_memcached.pid
# Standard LSB functions
#. /lib/lsb/init-functions
# Source function library.
. /etc/init.d/functions
SOCKET_PATH=/var/run/ipa_memcached/ipa_memcached
USER=apache
PIDFILE=/var/run/ipa_memcached/ipa_memcached.pid
MAXCONN=1024
CACHESIZE=64
OPTIONS=""
if [ -f /etc/sysconfig/ipa_memcached ];then
. /etc/sysconfig/ipa_memcached
fi
# Check that networking is up.
. /etc/sysconfig/network
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
prog="ipa_memcached"
pidfile=${PIDFILE-/var/run/ipa_memcached/ipa_memcached.pid}
lockfile=${LOCKFILE-/var/lock/subsys/ipa_memcached}
start () {
echo -n $"Starting $prog: "
# Ensure that $pidfile directory has proper permissions and exists
piddir=`dirname $pidfile`
if [ ! -d $piddir ]; then
mkdir $piddir
fi
if [ "`stat -c %U $piddir`" != "$USER" ]; then
chown $USER $piddir
fi
daemon --pidfile ${pidfile} /usr/bin/memcached -d -s ${SOCKET_PATH} -u ${USER} -m ${CACHESIZE} -c ${MAXCONN} -P ${pidfile} ${OPTIONS}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile}
return $RETVAL
}
stop () {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} $prog
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f ${lockfile} ${pidfile}
fi
return $RETVAL
}
restart () {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
# run checks to determine if the service is running or use generic status
status -p ${pidfile} $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
# See how we were called.
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?

5
init/ipa_memcached.conf Normal file
View File

@ -0,0 +1,5 @@
SOCKET_PATH=/var/run/ipa_memcached/ipa_memcached
USER=apache
MAXCONN=1024
CACHESIZE=64
OPTIONS=

View File

@ -0,0 +1 @@
d /var/run/ipa_memcached 0700 apache apache

View File

@ -0,0 +1,12 @@
[Unit]
Description=IPA memcached daemon, increases IPA server performance
After=network.target
[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/ipa_memcached
PIDFile=/var/run/ipa_memcached/ipa_memcached.pid
ExecStart=/usr/bin/memcached -d -s $SOCKET_PATH -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/ipa_memcached/ipa_memcached.pid $OPTIONS
[Install]
WantedBy=multi-user.target

View File

@ -48,6 +48,7 @@ from ipaserver.install import httpinstance
from ipaserver.install import ntpinstance from ipaserver.install import ntpinstance
from ipaserver.install import certs from ipaserver.install import certs
from ipaserver.install import cainstance from ipaserver.install import cainstance
from ipaserver.install import memcacheinstance
from ipaserver.install import service from ipaserver.install import service
from ipapython import version from ipapython import version
@ -988,6 +989,9 @@ def main():
os.write(pw_fd, options.http_pin) os.write(pw_fd, options.http_pin)
os.close(pw_fd) os.close(pw_fd)
memcache = memcacheinstance.MemcacheInstance()
memcache.create_instance('MEMCACHE', host_name, dm_password, util.realm_to_suffix(realm_name))
http = httpinstance.HTTPInstance(fstore) http = httpinstance.HTTPInstance(fstore)
if options.http_pkcs12: if options.http_pkcs12:
pkcs12_info = (options.http_pkcs12, pw_name) pkcs12_info = (options.http_pkcs12, pw_name)

View File

@ -0,0 +1,24 @@
# Authors: John Dennis <jdennis@redhat.com>
#
# Copyright (C) 2011 Red Hat
# 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 service
class MemcacheInstance(service.SimpleServiceInstance):
def __init__(self):
service.SimpleServiceInstance.__init__(self, "ipa_memcached")

View File

@ -38,6 +38,7 @@ SERVICE_LIST = {
'KDC':('krb5kdc', 10), 'KDC':('krb5kdc', 10),
'KPASSWD':('kadmin', 20), 'KPASSWD':('kadmin', 20),
'DNS':('named', 30), 'DNS':('named', 30),
'MEMCACHE':('ipa_memcached', 39),
'HTTP':('httpd', 40), 'HTTP':('httpd', 40),
'CA':('pki-cad', 50), 'CA':('pki-cad', 50),
'ADTRUST':('smb', 60) 'ADTRUST':('smb', 60)