<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-2022-jp">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
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="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I'm not sure if this is the correct list to ask this question, it's about systemd unit configuration.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">We have a 3rd party application that starts and stops via startup and shutdown scripts which we would like to have start up automatically at linux boot time.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The start script calls other scripts to start two application components and then the start script exits.<o:p></o:p></p>
<p class="MsoNormal">One of the application components also spawns a couple of child processes.<o:p></o:p></p>
<p class="MsoNormal">There ends up being two pid files, one for each component, describing the state of the application.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Below is an iteration of the unit service file for the application:<o:p></o:p></p>
<p class="MsoNormal">--------------------------------------------------------------------------------<o:p></o:p></p>
<p class="MsoNormal">[Unit]<o:p></o:p></p>
<p class="MsoNormal">Description=XXX Application<o:p></o:p></p>
<p class="MsoNormal">RequiresMountsFor=/ /opt /tmp<o:p></o:p></p>
<p class="MsoNormal">After=network-online.target sshd.service<o:p></o:p></p>
<p class="MsoNormal">Requires=sshd.service<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[Service]<o:p></o:p></p>
<p class="MsoNormal">Type=oneshot<o:p></o:p></p>
<p class="MsoNormal">User=xxx<o:p></o:p></p>
<p class="MsoNormal">UMask=0764<o:p></o:p></p>
<p class="MsoNormal">TimeoutSec=360s<o:p></o:p></p>
<p class="MsoNormal">LimitSTACK=infinity<o:p></o:p></p>
<p class="MsoNormal">LimitNOFILE=8192<o:p></o:p></p>
<p class="MsoNormal">Environment=HOME=/home/xxx<o:p></o:p></p>
<p class="MsoNormal">Environment=JAVA_HOME=/opt/xxx/jre<o:p></o:p></p>
<p class="MsoNormal">Environment=CLASSPATH=.:/opt/xxx/jre/lib<o:p></o:p></p>
<p class="MsoNormal">Environment=PATH=/opt/xxx/jre/bin:/opt/xxx/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin<o:p></o:p></p>
<p class="MsoNormal">WorkingDirectory=/opt/xxx/bin<o:p></o:p></p>
<p class="MsoNormal">RemainAfterExit=yes<o:p></o:p></p>
<p class="MsoNormal">ExecStart=/bin/bash -l /opt/xxx/bin/startApp.sh<o:p></o:p></p>
<p class="MsoNormal">ExecStop=-/bin/bash -lc "/opt/xxx/bin/stopApp.sh -np"<o:p></o:p></p>
<p class="MsoNormal">KillMode=none<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[Install]<o:p></o:p></p>
<p class="MsoNormal">WantedBy=multi-user.target<o:p></o:p></p>
<p class="MsoNormal">--------------------------------------------------------------------------------<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The above unit file works for starting and stopping the application both at boot and via:<o:p></o:p></p>
<p class="MsoNormal">systemctl start xxx<o:p></o:p></p>
<p class="MsoNormal">systemctl stop xxx<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">When I check the systemctl service status<o:p></o:p></p>
<p class="MsoNormal">$ systemctl list-units -t service<o:p></o:p></p>
<p class="MsoNormal"> UNIT LOAD ACTIVE SUB DESCRIPTION<o:p></o:p></p>
<p class="MsoNormal"> xxx.service loaded active exited XXX Application<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I think the RemainAfterExit directive tells systemd to show the ACTIVE state even though the startup script exited.<o:p></o:p></p>
<p class="MsoNormal">Both the loaded and active status make sense.<o:p></o:p></p>
<p class="MsoNormal">The low-level unit activation state of exited makes sense since the start script for the application exits after starting the application components.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">For some more info:<o:p></o:p></p>
<p class="MsoNormal">$ /bin/systemctl status xxx<o:p></o:p></p>
<p class="MsoNormal">● xxx.service - XXX Application<o:p></o:p></p>
<p class="MsoNormal"> Loaded: loaded (/etc/systemd/system/xxx.service; enabled; vendor preset: disabled)<o:p></o:p></p>
<p class="MsoNormal"> Active: active (exited) since Mon 2016-12-19 16:15:13 EST; 18h ago<o:p></o:p></p>
<p class="MsoNormal">Main PID: 15346 (code=exited, status=0/SUCCESS)<o:p></o:p></p>
<p class="MsoNormal"> CGroup: /system.slice/xxx.service<o:p></o:p></p>
<p class="MsoNormal"> <span style="font-family:"Arial","sans-serif"">├</span>─15402 /opt/xxx/jre/bin/java ...<o:p></o:p></p>
<p class="MsoNormal"> <span style="font-family:"Arial","sans-serif"">├</span>─16249 /opt/xxx/jre/bin/java ...<o:p></o:p></p>
<p class="MsoNormal"> <span style="font-family:"Arial","sans-serif"">├</span>─16893 /opt/xxx/...<o:p></o:p></p>
<p class="MsoNormal"> <span style="font-family:"Arial","sans-serif"">├</span>─16894 /opt/xxx/jre/bin/java ...<o:p></o:p></p>
<p class="MsoNormal"> <span style="font-family:"Arial","sans-serif"">├</span>─17146 /bin/sh /opt/xxx/...<o:p></o:p></p>
<p class="MsoNormal"> <span style="font-family:"Arial","sans-serif"">├</span>─17173 /opt/xxx/jre/bin/java ...<o:p></o:p></p>
<p class="MsoNormal"> <span style="font-family:"Arial","sans-serif"">├</span>─17201 /opt/xxx/...<o:p></o:p></p>
<p class="MsoNormal"> <span style="font-family:"Arial","sans-serif"">├</span>─17239 /opt/xxx/...<o:p></o:p></p>
<p class="MsoNormal"> └瘢雹─17945 /opt/xxx/jre/bin/java ...<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The Main PID: 15346 I assume was the pid for the startup script which exits.<o:p></o:p></p>
<p class="MsoNormal">Is there some way I can have systemd monitor the component pids to show ACTIVE status?<o:p></o:p></p>
<p class="MsoNormal">Is there a better way to configure the service unit – given that we have to use the 3<sup>rd</sup> party scripts?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:blue">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:blue"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:blue">Stephen R. Owens<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:blue">Senior Software Engineer<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:blue">Massachusetts Office of Information Technology<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:blue">Commonwealth of Massachusetts<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:blue">One Ashburton Place, Room 1611<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:blue">Boston, MA 02108<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:blue">Tel: 617-626-4513 x24513<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif";color:blue">Email:
<a href="mailto:Stephen.Owens@state.ma.us"><span style="color:blue">Stephen.Owens@state.ma.us</span></a><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>