I am attaching the patch now :)
>From 82f9545715332d78be921a1e6456eeca23f22086 Mon Sep 17 00:00:00 2001
From: Christos Trochalakis <yati...@ideopolis.gr>
Date: Tue, 30 Dec 2014 11:30:31 +0200
Subject: [PATCH 1/2] Use /etc/memcached.conf on systemd systems.

We do that by introducing a systemd wrapper that reads
/etc/memcached.conf end execs memcached with the correct options. This
makes sysvinit and systemd systems behave in the same way.

This scripts is basically start-memcached without the forking and
logfile logic, those are now handled by systemd.
---
 debian/memcached.service         |  2 +-
 debian/rules                     |  2 ++
 debian/systemd-memcached-wrapper | 62 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100755 debian/systemd-memcached-wrapper

diff --git a/debian/memcached.service b/debian/memcached.service
index 88fa963..14afb89 100644
--- a/debian/memcached.service
+++ b/debian/memcached.service
@@ -3,7 +3,7 @@ Description=memcached daemon
 After=network.target
 
 [Service]
-ExecStart=/usr/bin/memcached -p 11211 -u memcache -m 64 -c 1024 -l 127.0.0.1
+ExecStart=/usr/share/memcached/scripts/systemd-memcached-wrapper /etc/memcached.conf
 
 [Install]
 WantedBy=multi-user.target
diff --git a/debian/rules b/debian/rules
index be2bf68..98e8d46 100755
--- a/debian/rules
+++ b/debian/rules
@@ -26,6 +26,8 @@ override_dh_auto_install:
 	install -m 644 $(CURDIR)/debian/memcached.conf \
 		$(CURDIR)/$(PKGBASE)/memcached.conf.default
 	install -m 744 $(CURDIR)/scripts/start-memcached $(SCRIPTS)
+	install -m 755 $(CURDIR)/debian/systemd-memcached-wrapper \
+		$(SCRIPTS)
 	install -m 744 $(CURDIR)/scripts/memcached-tool $(SCRIPTS)
 	install -m 755 $(CURDIR)/scripts/memcached-init \
 		$(CURDIR)/debian/memcached.init
diff --git a/debian/systemd-memcached-wrapper b/debian/systemd-memcached-wrapper
new file mode 100755
index 0000000..90fb45f
--- /dev/null
+++ b/debian/systemd-memcached-wrapper
@@ -0,0 +1,62 @@
+#!/usr/bin/perl -w
+
+# systemd-memcached-wrapper
+# 2014 - Christos Trochalakis <yati...@idepolis.gr>
+#
+# Heavily based on start-memcached script by Jay Bonci
+# <jaybo...@debian.org>
+#
+# This script handles the parsing of the /etc/memcached.conf file
+# and was originally created for the Debian distribution.
+# Anyone may use this little script under the same terms as
+# memcached itself.
+
+use strict;
+
+if($> != 0 and $< != 0)
+{
+    print STDERR "Only root wants to run systemd-memcached-wrapper.\n";
+    exit;
+}
+
+my $params; my $etchandle; my $etcfile = "/etc/memcached.conf";
+
+# This script assumes that memcached is located at /usr/bin/memcached
+my $memcached = "/usr/bin/memcached";
+
+if (scalar(@ARGV) == 1) {
+    $etcfile = shift(@ARGV);
+}
+
+# systemd capture stdout by default
+my $ignore_directives = ("logfile");
+
+if(open $etchandle, $etcfile)
+{
+    foreach my $line (<$etchandle>)
+    {
+        $line ||= "";
+	$line =~ s/^\s*\#.*//g;
+        $line =~ s/\s+$//g;
+        $line =~ s/^\s+//g;
+        next unless $line;
+        next if $line =~ /^\-[dh]/;
+
+        if($line =~ /^[^\-]/)
+        {
+            my ($directive, $arg) = $line =~ /^(.*?)\s+(.*)/;
+	    next if(grep $directive, $ignore_directives);
+        }
+
+        push @$params, $line;
+    }
+
+}else{
+    $params = [];
+}
+
+push @$params, "-u root" unless(grep "-u", @$params);
+$params = join " ", @$params;
+
+exec "$memcached $params";
+exit(0);
-- 
2.1.4

Reply via email to