Skip to content

Commit

Permalink
FIX #770 add ExitStatusSuccess setting for systemd (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
muuki88 committed Jul 6, 2016
1 parent 085f947 commit 436e46c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ExecStart=${{chdir}}/bin/${{exec}}
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=${{retryTimeout}}
SuccessExitStatus=${{SuccessExitStatus}}
User=${{daemon_user}}
ExecStartPre=/bin/mkdir -p /run/${{app_name}}
ExecStartPre=/bin/chown ${{daemon_user}}:${{daemon_group}} /run/${{app_name}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ object SystemdPlugin extends AutoPlugin {

override def requires = SystemloaderPlugin

object autoImport {
val systemdSuccessExitStatus = settingKey[Seq[String]]("SuccessExitStatus property")
}

import autoImport._

override def projectSettings: Seq[Setting[_]] =
debianSettings ++ inConfig(Debian)(systemdSettings) ++ rpmSettings ++ inConfig(Rpm)(systemdSettings)

Expand All @@ -41,14 +47,17 @@ object SystemdPlugin extends AutoPlugin {
stopRunlevels := None,
requiredStartFacilities := Some("network.target"),
requiredStopFacilities := Some("network.target"),
systemdSuccessExitStatus := Seq.empty,
linuxStartScriptName := Some(packageName.value + ".service"),
// add systemloader to mappings
linuxPackageMappings ++= startScriptMapping(
linuxStartScriptName.value,
linuxMakeStartScript.value,
defaultLinuxStartScriptLocation.value,
isConf = true
)
),
// add additional system configurations to script replacements
linuxScriptReplacements += ("SuccessExitStatus" -> systemdSuccessExitStatus.value.mkString(" "))
)

def debianSettings: Seq[Setting[_]] = inConfig(Debian)(
Expand Down
3 changes: 3 additions & 0 deletions src/sbt-test/debian/systemd-deb/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ requiredStartFacilities in Debian := Some("network.target")

daemonUser in Linux := "testuser"

systemdSuccessExitStatus in Debian += "1"

TaskKey[Unit]("check-startup-script") <<= (target, streams) map { (target, out) =>
val script = IO.read(target / "debian-test-0.1.0" / "lib" / "systemd" / "system" / "debian-test.service")
assert(script.contains("Requires=network.target"), "script doesn't contain Default-Start header\n" + script)
assert(script.contains("User=testuser"), "script doesn't contain `User` header\n" + script)
assert(script.contains("EnvironmentFile=/etc/default/debian-test"), "script doesn't contain EnvironmentFile header\n" + script)
assert(script.contains("SuccessExitStatus=1"), "script doesn't contain SuccessExitStatus header\n" + script)
out.log.success("Successfully tested systemd start up script")
()
}
Expand Down
1 change: 1 addition & 0 deletions src/sbt-test/rpm/systemd-rpm/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ TaskKey[Unit]("checkStartupScript") <<= (target, streams) map { (target, out) =>
val script = IO.read(file("usr/lib/systemd/system/rpm-test.service"))
val runScript = file("usr/share/rpm-test/bin/rpm-test")
assert(script.contains("Requires=serviceA.service"), "script doesn't contain Default-Start header\n" + script)
assert(script.contains("SuccessExitStatus="), "script doesn't contain SuccessExitStatus header\n" + script)
out.log.success("Successfully tested systemd start up script")
()
}
Expand Down
8 changes: 8 additions & 0 deletions src/sphinx/archetypes/systemloaders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ In order to enable Systemd add this plugin:
enablePlugins(SystemdPlugin)
Settings
~~~~~~~~

``systemdSuccessExitStatus``
Takes a list of exit status definitions that when returned by the main service process will be considered successful
termination, in addition to the normal successful exit code ``0`` and the signals ``SIGHUP``, ``SIGINT``,
``SIGTERM``, and ``SIGPIPE``. Exit status definitions can either be numeric exit codes or termination signal names.

Upstart
-------

Expand Down

0 comments on commit 436e46c

Please sign in to comment.