[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Freeipa-devel] [PATCH 59] Modify spec file to add ipa_memcached service Install &, control ipa_memcached instance



rebased patch because it wouldn't apply to master

--
John Dennis <jdennis redhat com>

Looking to carve out IT costs?
www.redhat.com/carveoutcosts/
>From c11ca3aaed9dba7c2ac4b2de6b3eba8aeb641f53 Mon Sep 17 00:00:00 2001
From: John Dennis <jdennis redhat com>
Date: Mon, 6 Feb 2012 13:15:06 -0500
Subject: [PATCH 59-3] Add ipa_memcached service
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

* 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
---
 freeipa.spec.in                       |   22 ++++++
 init/SystemV/ipa_memcached.init       |  120 +++++++++++++++++++++++++++++++++
 init/ipa_memcached.conf               |    5 ++
 init/systemd/ipa.conf.tmpfiles        |    1 +
 init/systemd/ipa_memcached.service    |   13 ++++
 install/tools/ipa-server-install      |    4 +
 ipaserver/install/memcacheinstance.py |   26 +++++++
 ipaserver/install/service.py          |    1 +
 8 files changed, 192 insertions(+), 0 deletions(-)
 create mode 100755 init/SystemV/ipa_memcached.init
 create mode 100644 init/ipa_memcached.conf
 create mode 100644 init/systemd/ipa.conf.tmpfiles
 create mode 100644 init/systemd/ipa_memcached.service
 create mode 100644 ipaserver/install/memcacheinstance.py

diff --git a/freeipa.spec.in b/freeipa.spec.in
index bffeca2..a40368d 100644
--- a/freeipa.spec.in
+++ b/freeipa.spec.in
@@ -109,6 +109,8 @@ Requires: python-ldap
 Requires: python-krbV
 Requires: acl
 Requires: python-pyasn1 >= 0.0.9a
+Requires: memcached
+Requires: python-memcached
 %if 0%{?fedora} >= 16
 Requires: systemd-units >= 36-3
 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/preferences.html
 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
 # Default to systemd initscripts for F16 and above
 mkdir -p %{buildroot}%{_unitdir}
 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
 install -m755 init/SystemV/ipa.init %{buildroot}%{_initrddir}/ipa
+install -m755 init/SystemV/ipa_memcached.init %{buildroot}%{_initrddir}/ipa_memcached
 %endif
 %endif
 
@@ -491,12 +506,19 @@ fi
 %{_sbindir}/ipa-upgradeconfig
 %{_sbindir}/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
 # Use systemd scheme
 %attr(644,root,root) %{_unitdir}/ipa.service
+%attr(644,root,root) %{_unitdir}/ipa_memcached.service
 %else
 # Use SystemV scheme only before F16
 %attr(755,root,root) %{_initrddir}/ipa
+%attr(755,root,root) %{_initrddir}/ipa_memcached
 %endif
 %dir %{python_sitelib}/ipaserver
 %{python_sitelib}/ipaserver/*
diff --git a/init/SystemV/ipa_memcached.init b/init/SystemV/ipa_memcached.init
new file mode 100755
index 0000000..b30ea50
--- /dev/null
+++ b/init/SystemV/ipa_memcached.init
@@ -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 $?
diff --git a/init/ipa_memcached.conf b/init/ipa_memcached.conf
new file mode 100644
index 0000000..19d9127
--- /dev/null
+++ b/init/ipa_memcached.conf
@@ -0,0 +1,5 @@
+SOCKET_PATH=/var/run/ipa_memcached/ipa_memcached
+USER=apache
+MAXCONN=1024
+CACHESIZE=64
+OPTIONS=
diff --git a/init/systemd/ipa.conf.tmpfiles b/init/systemd/ipa.conf.tmpfiles
new file mode 100644
index 0000000..e4b679a
--- /dev/null
+++ b/init/systemd/ipa.conf.tmpfiles
@@ -0,0 +1 @@
+d /var/run/ipa_memcached 0700 apache apache
diff --git a/init/systemd/ipa_memcached.service b/init/systemd/ipa_memcached.service
new file mode 100644
index 0000000..33ace09
--- /dev/null
+++ b/init/systemd/ipa_memcached.service
@@ -0,0 +1,13 @@
+[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
+
diff --git a/install/tools/ipa-server-install b/install/tools/ipa-server-install
index b913438..949d021 100755
--- a/install/tools/ipa-server-install
+++ b/install/tools/ipa-server-install
@@ -48,6 +48,7 @@ from ipaserver.install import httpinstance
 from ipaserver.install import ntpinstance
 from ipaserver.install import certs
 from ipaserver.install import cainstance
+from ipaserver.install import memcacheinstance
 
 from ipaserver.install import service
 from ipapython import version
@@ -988,6 +989,9 @@ def main():
         os.write(pw_fd, options.http_pin)
         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)
     if options.http_pkcs12:
         pkcs12_info = (options.http_pkcs12, pw_name)
diff --git a/ipaserver/install/memcacheinstance.py b/ipaserver/install/memcacheinstance.py
new file mode 100644
index 0000000..91c8636
--- /dev/null
+++ b/ipaserver/install/memcacheinstance.py
@@ -0,0 +1,26 @@
+# 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")
+
+
diff --git a/ipaserver/install/service.py b/ipaserver/install/service.py
index d9e6def..467e604 100644
--- a/ipaserver/install/service.py
+++ b/ipaserver/install/service.py
@@ -38,6 +38,7 @@ SERVICE_LIST = {
     'KDC':('krb5kdc', 10),
     'KPASSWD':('kadmin', 20),
     'DNS':('named', 30),
+    'MEMCACHE':('ipa_memcached', 39),
     'HTTP':('httpd', 40),
     'CA':('pki-cad', 50),
     'ADTRUST':('smb', 60)
-- 
1.7.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]