<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Ellipsis: Apache and "shared memory" issues on Linux</title>
    <link>http://typo.pburkholder.com/articles/2008/04/10/apache-and-shared-memory-issues-on-linux</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>...</description>
    <item>
      <title>Apache and &amp;quot;shared memory&amp;quot; issues on Linux</title>
      <description>&lt;p&gt;This morning I was having trouble getting Apache (2.0.X) to restart.  I was getting these error messages:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
[Thu Apr 10 08:32:49 2008] [crit] (17)File exists: unable to create scoreboard "/var/private/logs/apache_runtime_status" (name-based shared memory failure)
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;and I kept deleting the offending file, and making sure that permissions all along the path were correct.  No dice.&lt;/p&gt;


	&lt;p&gt;So I restarted Apache again running &lt;code&gt;strace&lt;/code&gt;:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
strace /usr/sbin/httpd2-prefork -X -Dprivate '-CPidFile /var/run/apache2.private.pid' -f /etc/apache2/httpd.conf
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;and saw output like this:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
unlink("/var/private/logs/apache_runtime_status") = -1 ENOENT (No such file or directory)
open("/var/private/logs/apache_runtime_status", O_WRONLY|O_CREAT|O_EXCL, 0666) = 9
stat("/var/private/logs/apache_runtime_status", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
shmget(16908303, 40824, IPC_CREAT|IPC_EXCL|0600) = -1 EEXIST (File exists)
write(2, "[Thu Apr 10 08:18:46 2008] [crit"..., 168) = 168
&lt;/pre&gt;&lt;/code&gt;

	&lt;h2&gt;Red Herring&lt;/h2&gt;


	&lt;p&gt;Turns out that worrying about the filesystem was a distraction.  The real issue is that the previous Apache had left behind shared memory segments that it couldn&amp;#8217;t access anymore.  Now I won&amp;#8217;t pretend that I understand the ins and outs of shared memory on Linux, but a bit of Googling led me, fortunately to &lt;a href="http://www.siphos.be/node/29"&gt;Sven Vermeulen&amp;#8217;s blog&lt;/a&gt;, where he shared a similar experience on Solaris.  I would&amp;#8217;ve left nice comments on his blog, but as he doesn&amp;#8217;t take comments, I&amp;#8217;ll give a shout out to him here.&lt;/p&gt;


	&lt;p&gt;Anyhow, the &lt;strong&gt;ipcs&lt;/strong&gt; and &lt;strong&gt;ipcrm&lt;/strong&gt; commands come to the rescue:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
# ipcs -a

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x0102000f 99942402   root      600        40824      0

------ Semaphore Arrays --------
key        semid      owner      perms      nsems

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages
0x00001f58 0          root       600        0            0
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;Ah-ha&amp;#8212;there&amp;#8217;s &lt;strong&gt;shmid&lt;/strong&gt; at 99942402.  Let&amp;#8217;s rm that:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
# ipcrm -m 99942402
# ipcs -a

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status

------ Semaphore Arrays --------
key        semid      owner      perms      nsems

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages
0x00001f58 0          root       600        0            0
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;And apache started right up.  Yea.&lt;/p&gt;


	&lt;p&gt;P.S. One find out more about a shared memory segment with something like: &lt;code&gt;ipcs -m -i 99942402&lt;/code&gt;, which will report:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
Shared memory Segment shmid=99942402
uid=0   gid=0   cuid=0  cgid=0
mode=0600       access_perms=0600
bytes=40824     lpid=6987       cpid=6987       nattch=0
att_time=Thu Apr 10 08:20:48 2008  
det_time=Thu Apr 10 08:21:55 2008  
change_time=Thu Apr 10 08:20:48 2008  

&lt;/pre&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 10 Apr 2008 06:07:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:bdb73e1d-bb02-4e94-a6b5-5e2a6de646d6</guid>
      <author>Peter Burkholder</author>
      <link>http://typo.pburkholder.com/articles/2008/04/10/apache-and-shared-memory-issues-on-linux</link>
      <category>System Administration</category>
      <category>Web Development</category>
      <category>apache</category>
    </item>
    <item>
      <title>"Apache and "shared memory" issues on Linux" by christt</title>
      <description>Thanks Peter!

You saved my day!
</description>
      <pubDate>Mon, 03 Nov 2008 13:23:52 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:bbed8b4f-8a6e-4704-b6ea-b5f170fad1e8</guid>
      <link>http://typo.pburkholder.com/articles/2008/04/10/apache-and-shared-memory-issues-on-linux#comment-4012</link>
    </item>
    <item>
      <title>"Apache and "shared memory" issues on Linux" by rizahnst</title>
      <description>thanks!</description>
      <pubDate>Wed, 16 Jul 2008 03:23:32 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:d151670c-2841-48d8-9e38-31d9e8d13a17</guid>
      <link>http://typo.pburkholder.com/articles/2008/04/10/apache-and-shared-memory-issues-on-linux#comment-4007</link>
    </item>
    <item>
      <title>"Apache and "shared memory" issues on Linux" by Anny</title>
      <description>I have wanted one of these forever! THANKS for the great work</description>
      <pubDate>Sun, 20 Apr 2008 00:39:59 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:b48bec60-3631-4a4b-973a-1fddfa99b024</guid>
      <link>http://typo.pburkholder.com/articles/2008/04/10/apache-and-shared-memory-issues-on-linux#comment-4001</link>
    </item>
  </channel>
</rss>
