{"id":7718,"date":"2018-09-20T14:47:25","date_gmt":"2018-09-20T06:47:25","guid":{"rendered":"http:\/\/rmohan.com\/?p=7718"},"modified":"2018-09-20T14:48:20","modified_gmt":"2018-09-20T06:48:20","slug":"apache-2-4-ah01762-ah01760-failed-to-initialize-shm-shared-memory-segment","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7718","title":{"rendered":"Apache 2.4 AH01762 &#038; AH01760: failed to initialize shm (Shared Memory Segment)"},"content":{"rendered":"<h1>Apache 2.4 AH01762 &amp; AH01760: failed to initialize shm (Shared Memory Segment)<\/h1>\n<p><small class=\"meta_date\">Mattias Geniar, Tuesday, January 12, 2016<\/small><\/p>\n<div class=\"blogpost_content\">\n<p>I recently ran into the following problem on an Apache 2.4 server, where after server reboot the service itself would no longer start.<\/p>\n<p>This was the error whenever I tried to start it:<\/p>\n<pre>$ tail -f error.log\r\n[auth_digest:error] [pid 11716] (2)No such file or directory:\r\n   AH01762: Failed to create shared memory segment on file \/run\/httpd\/authdigest_shm.11716\r\n[auth_digest:error] [pid 11716] (2)No such file or directory:\r\n   AH01760: failed to initialize shm - all nonce-count checking, one-time nonces,\r\n   and MD5-sess algorithm disabled\r\n<\/pre>\n<p>Systemd reported the same problem;<\/p>\n<pre>$ systemctl status -l httpd.service\r\n - httpd.service - The Apache HTTP Server\r\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/httpd.service; enabled; vendor preset: disabled)\r\n   Active: failed (Result: exit-code) since ...\r\n<\/pre>\n<p>The cause is shown in the first error message:\u00a0<strong>Failed to create shared memory segment on file \/run\/httpd\/authdigest_shm.11716<\/strong>.<\/p>\n<p>If I traced this, I noticed the directory\u00a0<code>\/run\/httpd<\/code>\u00a0no longer existed. The simple fix in this case, was to re-create that missing directory.<\/p>\n<pre>$ mkdir \/run\/httpd\r\n$ chown root:httpd \/run\/httpd\r\n$ chmod 0710 \/run\/httpd\r\n<\/pre>\n<p>The directory should be owned by root and writeable for the root user. The Apache group (in my case,\u00a0<code>httpd<\/code>), needs executable rights to look into the directory.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p>iven facility which allows non-dependent subsystems to be started, controlled, or stopped in parallel. Here we explain how to add a custom script to the systemd facility.<\/p>\n<h2>1. Write And Debug The Custom Script<\/h2>\n<p>Typically a systemd script is written as a shell script. Begin by writing your custom script using the normal conventions. We will call our script my-custom-script.sh and is straightforward:<\/p>\n<div class=\"codeme\">\n<pre>#!\/bin\/sh\r\necho \"I am a custom script\" &gt; \/var\/tmp\/script.out\r\necho \"The script was run at : `date`\" &gt;&gt; &gt; \/var\/tmp\/script.out<\/pre>\n<\/div>\n<p>The script must be executable.<\/p>\n<div>\n<p><ins class=\"adsbygoogle square-responsive\" data-full-width-responsive=\"true\" data-ad-client=\"ca-pub-9806101468749934\" data-ad-slot=\"7337034404\" data-adsbygoogle-status=\"done\"><ins id=\"aswift_1_expand\"><ins id=\"aswift_1_anchor\"><\/ins><\/ins><\/ins><span style=\"font-family: Consolas, Monaco, monospace;\"># chmod 0755 \/var\/tmp\/my-custom-script.sh<\/span><\/p>\n<\/div>\n<h2>2. Describe The Custom Script To systemd<\/h2>\n<p>With the script written and tested manually, the script is ready to be described to the systemd system. To do this, a\u00a0<strong>[name].service<\/strong>\u00a0file is needed. The syntax uses the INI format commonly used for configuration files. Continuing our example, we need a my-custom-script.service file. The executable will run exactly once for each time the service is started. The service will not be started until the networking layer is up and stable.<\/p>\n<p>Create a new service unit file at \/etc\/systemd\/system\/my-custom-script.service with below content. The name of the service unit is user defined and can be any name of your choice.<\/p>\n<div class=\"codeme\">\n<pre># This is my-custom-script.service, which describes the my-custom-script.sh file\r\n[Unit]\r\nDescription=This is executed on shutdown or reboot\r\nDefaultDependencies=no\r\nWants=network-pre.target                                                                   # (if network is required before running the script)\r\nBefore=network-pre.target shutdown.target reboot.target halt.target                        # Defines the order in which units are stoped. #(REQUIRED)\r\n\r\n[Service]\r\nType=oneshot                                                                               # enables specifying multiple custom commands that are then executed sequentially. (REQUIRED)\r\nRemainAfterExit=true                                                                       # required by the oneshot setting (REQUIRED)\r\nEnvironment=ONE='one' \"TWO='2\"                                                             # you can set some environment variables, that may be necessary to pass as arguments\r\nExecStart=\/bin\/true                                                                        # because is a shutdown script nothing is done when this service is started\r\nExecStop=\/bin\/bash \/var\/tmp\/my-custom-script.sh ${ONE} ${TWO}                              # &lt; --*********** change to the script full path ************ (REQUIRED)\r\nTimeoutStopSec=1min 35s                                                                    # Configures the time to wait for stop. \r\n\r\n[Install]\r\nWantedBy=multi-user.target                                                                 # When this unit is enabled, the units listed in WantedBy gain a Want dependency on the unit. (REQUIRED)<\/pre>\n<\/div>\n<h2>3. Enable The Script For Future Reboots<\/h2>\n<p>Similar to the chkconfig from earlier versions, the service must be enabled. Since a new service was added, notify the systemd daemon to reconfigure itself:<\/p>\n<div class=\"codeme\">\n<pre># systemctl enable my-custom-script.service\r\n# systemctl daemon-reload<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Apache 2.4 AH01762 &amp; AH01760: failed to initialize shm (Shared Memory Segment) <\/p>\n<p>Mattias Geniar, Tuesday, January 12, 2016<\/p>\n<p>I recently ran into the following problem on an Apache 2.4 server, where after server reboot the service itself would no longer start.<\/p>\n<p>This was the error whenever I tried to start it:<\/p>\n<p> $ tail -f error.log [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7718"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7718"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7718\/revisions"}],"predecessor-version":[{"id":7720,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7718\/revisions\/7720"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}