[systemd-devel] preparing unit definition for squid – some questions

Tomasz Torcz tomek at pipebreaker.pl
Thu Nov 25 13:43:44 PST 2010


Hi,

  I'm slowly porting init scripts of software I use to systemd unit files.
It is generally straight-forward, but today Squid made me wonder.

  Squid is web-caching daemon (proxy) with some pecularities.  It
stores the cache of the internet in some directories on disk.  To
paralleize access, it is recommended to define separate cache_dir for
each hard disk. Also, squid likes 2-level deep folder structure
in each cache_dir, to implement simple hashing and deal with lesser
filesystems.

  Populating each defined cache_dir can be slow operation, therefore
it is not done automatically.  Fedora's squid script checks if cache_dir
is empty and if so, run the command to create folder hierarchy.

  This “populate” command is great candidate for separating into its own
unit, squid-populate.service, required by main squid.service and
using negated ConditionDirectoryNotEmpty=.

  As I mentioned, there could be more than one cache_dir definition.
For each one, separate squid-populate.service should be created, using
@ instances. (BTW, we cannot grep-out all the directories from
squid.conf, administrator needs to repeat cache_dir configuration in
systemd units).

  Now the question:  how should requires be defined?  Which is better way?
1) should squid.service explicitly require squid-populate@/var/spool/squid/cache1.service,
   …cache2.service etc?  This means that administrator would need to
  modify main squid.service when adding more cache_dirs

or

2) should each instance define itself as required by squid.service?  If so,
   how to do it?
   This behaviour makes adding directories simpler.

  Nb. I consider using unit generator parsing squid.conf an overkill for
this task :)


  Second issue, cascading timeouts.  Let's say squid-populate.service has TimeoutSec=3m,
because it may be slow.  Main squid.service has standard 1m timeout.
What happen when I run "systemctl start squid.service" with empty cache
directory? squid-populate.service will be started and may work for, let's
say, 2 minutes.  Will systemctl timeout after 1m?  Or after 3m+1m?

  In future squid may be socket-activable.  If population is needed, will
the timeout for connection be 3m (populate) + 1m (squid itself) + 1m (socket
timeout) = 5m ?

  Side observation: systemd has only one timeout for start and stop.
Squid's sysv script defines short timeout for start and much longer
for stop (because squid waits for open connection to end when closing).

-- 
Tomasz Torcz                 Morality must always be based on practicality.
xmpp: zdzichubg at chrome.pl                -- Baron Vladimir Harkonnen



More information about the systemd-devel mailing list