<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Jonathan;<br><br>Thanks for the background and information. Since you clearly seem to have a grasp of systemd please humour me with a few more questions (some of them slightly ignorant):<br><br>a) Why are PID bad?<br>b) Why are lock files bad?<br>c) If a/b are so bad why did they persist for so many years in SysVInit?<br>d) Generically, how would you prescribe to use systemd to start Java processes (for Java application servers) that are typically started from a set of relatively complex scripts that are used to set up the environment before launching the Java process? It seems that you are advocating to call, as directly as possible, the target service/daemon. However, some things don't seem so straight-forward.<br><br>Thanks again!<br>Lesley Kimmel, RHCE<br>Unix/Linux Systems Engineer<br><br><div>> Date: Sun, 28 Jun 2015 14:29:40 +0100<br>> From: J.deBoynePollard-newsgroups@NTLWorld.com<br>> To: systemd-devel@lists.freedesktop.org<br>> Subject: Re: [systemd-devel] SysVInit service migration to systemd<br>> <br>> Lesley Kimmel:<br>> > I've been working with RHEL5/6 for the past several years and have <br>> > developed many init scripts/services which generally use lock files <br>> > and PID files to allow for tracking of the service status. We are <br>> > moving to RHEL7 (systemd) in the near future and I am looking for <br>> > instruction or tutorials on how to effectively migrate these scripts <br>> > to work with systemd. [...] It looks like I may be able to use the <br>> > 'forking' type with the 'pidfile' parameter to somewhat mimic what the <br>> > scripts to today.<br>> <br>> You don't do such migration. You understand how your daemons are <br>> started, and you write service (and other) units to describe that. You <br>> do not start with the assumption that you migrate straight from one to <br>> the other, particularly if your existing mechanisms involve the <br>> dangerous and rickety things (e.g. PID files) that proper service <br>> management is designed to avoid in the first place, or things such as <br>> "subsystem" lock files which proper service management has no need of by <br>> its very nature. "Type=forking" specifies a quite specific readiness <br>> protocol that your daemon has to enact, lest it be regarded as failed. <br>> It's isn't a catch-all for anything that might fork in any possible <br>> way. And service managers know, by dint of simply remembering, what <br>> processes they started and whether they've already started them.<br>> <br>> I've been collecting case studies of people who have migrated to systemd <br>> exceedingly badly, and constructed some quite horrendous systems, <br>> because they've done so without either consideration of, or <br>> understanding of, how their sytems actually work. Here's one candidate <br>> that I have yet to add, because I'm hoping that now they've been told <br>> that they are going wrong they will correct themselves, whose errors are <br>> good to learn from.<br>> <br>> There's a computer game called "ARK: Survival Evolved". It's daemon is <br>> a program named ShooterGameServer. To run this program continually as a <br>> daemon, someone named Federico Zivolo and a couple of other unidentified <br>> people came up with the somewhat bizarre idea of running it under <br>> screen, and using screen's commands to send its pseudo-terminal an <br>> interrupt character, in order to send a SIGINT to the daemon when it <br>> came time to shut it down. They wrapped this up in a System 5 rc <br>> script, taking the conventional "start" and "stop" verbs, named <br>> "arkmanager". Its prevent-multiple-instances system was not lock files, <br>> but grepping the process table.<br>> <br>> Wrapped around this they put another System 5 rc script, named <br>> "arkdaemon", which also took the conventional "start" and "stop" verbs, <br>> and which treated the wrapper "arkmanager" script as the daemon, <br>> recording the process ID of the shell interpreter for the "arkmanager" <br>> script in a PID file, as if it were the actual daemon's process ID. It <br>> also did various other bad things that proper service managers <br>> eliminate, including grepping the process table (again), abusing su to <br>> drop privileges, using arbitrary 5 second sleeps to make the timing <br>> almost work, and (sic) hardwired ECMA-48 SGR sequences to change the <br>> colour of output that isn't going to a terminal in the first place.<br>> <br>> Then they wrote a systemd service unit file, "arkdeamon.service" (sic), <br>> that did this:<br>> <br>> > ExecStart=/etc/init.d/arkdaemon start<br>> > ExecStop=/etc/init.d/arkdaemon stop<br>> > Type=forking<br>> <br>> A couple of days ago, I pointed out the errors of even starting down <br>> this route to them, and wrote a systemd unit file for them that actually <br>> starts the daemon directly from systemd; no PID files, abuses of su, <br>> racy grepping of the process table, abritrary sleeps, or incorrect <br>> "forking" readiness protocol necessary. Set the account with User= ; <br>> set the environment with Environment= ; and run the program with <br>> ExecStart=/home/steam/ARK/ShooterGame/Binaries/Linux/ShooterGameServer <br>> plus some options. Other stuff, like software upgrades, one then builds <br>> on top of the service management layer, not beneath it. I also pointed <br>> out to them that I had been beaten in this regard by some 4 days by the <br>> (again unfortunately unidentified) people who wrote <br>> http://ark.gamepedia.com/Dedicated_Server_Setup#Automatic_Startup , <br>> whose service unit was pretty much the same as the one that I had <br>> independently written (as one would expect, indeed).<br>> <br>> If you understand how your daemon is run in the first place, then you <br>> end up with what I and the gamepedia people did. If you just think that <br>> you wrap what you already have, using "forking" to imperfectly paper <br>> over the cracks, you oftentimes end up with an utterly horrendous mess.<br>> _______________________________________________<br>> systemd-devel mailing list<br>> systemd-devel@lists.freedesktop.org<br>> http://lists.freedesktop.org/mailman/listinfo/systemd-devel<br></div> </div></body>
</html>