<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:PMingLiU;
panose-1:2 2 5 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@PMingLiU";
panose-1:2 2 5 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:ZH-TW;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoNoSpacing, li.MsoNoSpacing, div.MsoNoSpacing
{mso-style-priority:1;
margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:ZH-TW;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Hello,</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">I’m interested in a particular scenario which has been mentioned on mailing lists before:</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""><a href="https://www.mail-archive.com/search?l=systemd-devel@lists.freedesktop.org&q=subject:%22%5C%5Bsystemd%5C-devel%5C%5D+after%3Duser.slice+not+enforced%22&o=newest&f=1">https://www.mail-archive.com/search?l=systemd-devel@lists.freedesktop.org&q=subject:%22%5C%5Bsystemd%5C-devel%5C%5D+after%3Duser.slice+not+enforced%22&o=newest&f=1</a></span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">about stopping a database service. For the moment I’m considering the simplest case where systemd controls both the start and stopping of the service (though I’m mainly interested
in the stop).</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">What I’m finding in testing is that I cannot find an approach that stops the service before its user processes get killed first.</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Following the discussion in the article above I planned to have an additional target that existed after multi-user.target – post-multi-user.target (a bit like graphical.target). The
new target initially seemed like over-kill but I thought it would be the best way to order the shutdown.</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">[root@lab01 ~]# systemd-analyze critical-chain</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">The time after the unit is active or started is printed after the "@" character.</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">The time the unit takes to start is printed after the "+" character.</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">post-multi-user.target @42.912s</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">„€multi-user.target @42.911s</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> „€postfix.service @41.143s +1.766s</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> „€network.target @41.121s</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> „€network.service @39.661s +1.457s</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">...</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">I find that stopping and starting the service works fine as does isolating the target (actual config below) e.g.</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">e.g.</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""># systemctl stop dbora.service</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""># systemctl start dbora.service</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""># systemctl isolate multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""># systemctl isolate post-multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">But if I reboot I can see from the logs that a key process has gone before the shutdown script has run. This means the database has not had a chance to have a clean shutdown.</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Is the scenario I’m after something I can configure for? I’m sure it would be a popular use case. I can’t have the sessions I see in CGROUP name=systemd:/user.slice/ being killed before
my stop script has completed – it has to hold-up that process.</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">My test configuration looks like:</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">lab01.localdomain-root [] /lib/systemd/system# systemctl get-default</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">post-multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">lab01.localdomain-root [] /lib/systemd/system# cat dbora.service</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">[Unit]</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Description=The Oracle Database Service</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Requires=post-multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">After=post-multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">[Service]</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Type=oneshot</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">RemainAfterExit=yes</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">KillMode=none</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""># Set this to something larger if it has an impact</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">TimeoutStopSec=0</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">ExecStart=/u01/app/oracle/product/12.1.0.2/dbhome_1/bin/dbora start</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">ExecStop=/u01/app/oracle/product/12.1.0.2/dbhome_1/bin/dbora stop</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">[Install]</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""># Puts wants directive for the other units in the relationship</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">WantedBy=post-multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">lab01.localdomain-root [] /lib/systemd/system# cat post-multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">[Unit]</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Description=A level after multi-user for e.g. databases to run in</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Requires=multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Wants=dbora.service</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">After=multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">AllowIsolate=yes</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Sanity check config:</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">lab01.localdomain-root [] /lib/systemd/system# systemctl show -p Requires,Wants,Requisite,BindsTo,PartOf,Before,After post-multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Requires=multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Requisite=</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Wants=systemd-readahead-replay.service systemd-readahead-collect.service dbora.service</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">BindsTo=</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">PartOf=</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Before=systemd-readahead-done.service systemd-readahead-done.timer dbora.service</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">After=multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">lab01.localdomain-root [] /lib/systemd/system# systemctl show -p Requires,Wants,Requisite,BindsTo,PartOf,Before,After dbora.service</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Requires=basic.target post-multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Requisite=</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Wants=system.slice</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">BindsTo=</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">PartOf=</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">Before=shutdown.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">After=post-multi-user.target system.slice systemd-journald.socket basic.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">lab01.localdomain-root [] /lib/systemd/system#</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">lab01.localdomain-root [] /lib/systemd/system# systemd-analyze verify dbora.service</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">lab01.localdomain-root [] /lib/systemd/system# systemd-analyze verify post-multi-user.target</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New"">lab01.localdomain-root [] /lib/systemd/system#</span><o:p></o:p></p>
<p class="MsoNoSpacing"><span lang="EN-GB" style="font-family:"Courier New""> </span><o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"><b><span lang="EN-GB" style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#0085CA">Ray Nichols</span></b><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.0pt;font-family:"Arial",sans-serif">Oracle DBA</span><o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</body>
</html>