From a86b838f191eb34d15356852322cc02526ed461f12b644a3184e25e80bf24e92 Mon Sep 17 00:00:00 2001 From: Martin Pluskal Date: Wed, 22 Mar 2017 15:16:54 +0000 Subject: [PATCH] Accepting request 482004 from server:proxy:Test - initialize_cache_if_needed.sh, squid_dir.sed: Initialize cache directory on startup if it is missing. Move scripts out of systemd service file and into individual files. (bnc#1030421) OBS-URL: https://build.opensuse.org/request/show/482004 OBS-URL: https://build.opensuse.org/package/show/server:proxy/squid?expand=0&rev=117 --- cache_dir.sed | 7 +++++++ initialize_cache_if_needed.sh | 13 +++++++++++++ squid.changes | 7 +++++++ squid.service | 2 +- squid.spec | 7 +++++++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 cache_dir.sed create mode 100644 initialize_cache_if_needed.sh diff --git a/cache_dir.sed b/cache_dir.sed new file mode 100644 index 0000000..372c0b4 --- /dev/null +++ b/cache_dir.sed @@ -0,0 +1,7 @@ +#!/usr/bin/sed -nf + +/^\s*cache_dir\s\+[[:alnum:]]\+\s\+\([[:graph:]\/]\+\)\s.*/ { + s//\1\/00/p + q +} + diff --git a/initialize_cache_if_needed.sh b/initialize_cache_if_needed.sh new file mode 100644 index 0000000..e762dae --- /dev/null +++ b/initialize_cache_if_needed.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +DIR=$(dirname $0) +CACHE_DIR=$($DIR/cache_dir.sed < /etc/squid/squid.conf) +if [ 'x'$CACHE_DIR = 'x' ]; then + exit 0 +fi + +if ! test -d $CACHE_DIR; then + echo "Initializing cache directories..." + exec /usr/sbin/squid -z -F -N -S -f /etc/squid/squid.conf +fi + diff --git a/squid.changes b/squid.changes index a3331d8..95218e4 100644 --- a/squid.changes +++ b/squid.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Wed Mar 22 14:28:05 UTC 2017 - adam.majer@suse.de + +- initialize_cache_if_needed.sh, squid_dir.sed: Initialize cache + directory on startup if it is missing. Move scripts out of + systemd service file and into individual files. (bnc#1030421) + ------------------------------------------------------------------- Mon Jan 30 09:33:08 UTC 2017 - adam.majer@suse.de diff --git a/squid.service b/squid.service index 3862131..ab3bd3f 100644 --- a/squid.service +++ b/squid.service @@ -5,7 +5,7 @@ After=network.target named.service nss-lookup.service [Service] Type=forking EnvironmentFile=-/etc/sysconfig/squid -ExecStartPre=/bin/sh -c "test -d \"`sed -n 's/^cache_dir\s\+[[:alnum:]]\+\s\+\([[:graph:]\/]\+\)\s.*/\1/p' /etc/squid/squid.conf | sed '1 q'`/00\" || /usr/sbin/squid -z -F -N -S -f /etc/squid/squid.conf" +ExecStartPre=%{_libdir}/squid/initialize_cache_if_needed.sh ExecStart=/usr/sbin/squid -F $SQUID_START_OPTIONS -f /etc/squid/squid.conf ExecReload=/usr/sbin/squid -F $SQUID_START_OPTIONS -f /etc/squid/squid.conf -k reconfigure ExecStop=/usr/sbin/squid -F -f /etc/squid/squid.conf -k shutdown diff --git a/squid.spec b/squid.spec index 80c2e83..a62819b 100644 --- a/squid.spec +++ b/squid.spec @@ -38,6 +38,8 @@ Source10: README.kerberos Source11: %{name}.service Source13: %{name}.keyring Source14: squid.init.rh +Source15: cache_dir.sed +Source16: initialize_cache_if_needed.sh # do not show some rpmlint warnings Source99: squid-rpmlintrc @@ -259,6 +261,9 @@ fdupes -q -n -r %{buildroot}%{_prefix} # systemd vs SysVinit %if 0%{?has_systemd} install -D -m 644 %{SOURCE11} %{buildroot}%{_unitdir}/%{name}.service + install -D -m 755 %{SOURCE15} %{buildroot}%{squidlibdir}/cache_dir.sed + install -D -m 755 %{SOURCE16} %{buildroot}%{squidlibdir}/initialize_cache_if_needed.sh + sed -i -e 's!%%{_libdir}!%{_libdir}!' %{buildroot}%{_unitdir}/%{name}.service ln -sf %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name} %else # SysVinit # fix postrotate script for SysVinit @@ -406,6 +411,8 @@ end %doc %{_mandir}/man?/* %if 0%{?has_systemd} %{_unitdir}/%{name}.service +%{squidlibdir}/initialize_cache_if_needed.sh +%{squidlibdir}/cache_dir.sed %else %{_sysconfdir}/init.d/%{name} %endif