-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from kardapoltsev/wip/systemd
FIX #249. Systemd support for Debian and Rpm
- Loading branch information
Showing
21 changed files
with
219 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/post-rpm-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
systemctl enable ${{app_name}}.service | ||
systemctl start ${{app_name}}.service || echo "${{app_name}} could not be started. Try manually with service ${{app_name}} start" |
2 changes: 2 additions & 0 deletions
2
src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/postinst-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
systemctl enable ${{app_name}}.service | ||
systemctl start ${{app_name}}.service || echo "${{app_name}} could not be started. Try manually with service ${{app_name}} start" |
1 change: 1 addition & 0 deletions
1
src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/postrm-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
systemctl disable ${{app_name}}.service |
12 changes: 12 additions & 0 deletions
12
src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/postun-rpm-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Removing system user/group : ${{daemon_user}} and ${{daemon_group}} | ||
echo "Try deleting system user and group [${{daemon_user}}:${{daemon_group}}]" | ||
if getent passwd | grep -q "^${{daemon_user}}:"; | ||
then | ||
echo "Deleting system user: ${{daemon_user}}" | ||
userdel ${{daemon_user}} | ||
fi | ||
if getent group | grep -q "^${{daemon_group}}:" ; | ||
then | ||
echo "Deleting system group: ${{daemon_group}}" | ||
groupdel ${{daemon_group}} | ||
fi |
11 changes: 11 additions & 0 deletions
11
src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/pre-rpm-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Adding system user/group : ${{daemon_user}} and ${{daemon_group}} | ||
if ! getent group | grep -q "^${{daemon_group}}:" ; | ||
then | ||
echo "Creating system group: ${{daemon_group}}" | ||
groupadd --system ${{daemon_group}} | ||
fi | ||
if ! getent passwd | grep -q "^${{daemon_user}}:"; | ||
then | ||
echo "Creating system user: ${{daemon_user}}" | ||
useradd --gid ${{daemon_group}} --no-create-home --system -c '${{descr}}' ${{daemon_user}} | ||
fi |
1 change: 1 addition & 0 deletions
1
src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/prerm-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
systemctl ${{app_name}} stop || echo "${{app_name}} wasn't even running!" |
3 changes: 3 additions & 0 deletions
3
src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/preun-rpm-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Halting ${{app_name}} | ||
echo "Shutdown ${{app_name}}" | ||
systemctl stop ${{app_name}} |
13 changes: 13 additions & 0 deletions
13
src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/start-debian-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=${{descr}} | ||
Requires=${{start_facilities}} | ||
|
||
[Service] | ||
Type=simple | ||
WorkingDirectory=${{chdir}} | ||
ExecStart=${{chdir}}/bin/${{app_name}} | ||
Restart=always | ||
RestartSec=${{retryTimeout}} | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
13 changes: 13 additions & 0 deletions
13
src/main/resources/com/typesafe/sbt/packager/archetypes/systemd/start-rpm-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=${{descr}} | ||
Requires=${{start_facilities}} | ||
|
||
[Service] | ||
Type=simple | ||
WorkingDirectory=${{chdir}} | ||
ExecStart=${{chdir}}/bin/${{app_name}} | ||
Restart=always | ||
RestartSec=${{retryTimeout}} | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import NativePackagerKeys._ | ||
import com.typesafe.sbt.packager.archetypes.ServerLoader | ||
|
||
packageArchetype.java_server | ||
|
||
serverLoading in Debian := ServerLoader.Systemd | ||
|
||
name := "debian-test" | ||
|
||
version := "0.1.0" | ||
|
||
maintainer := "Alexey Kardapoltsev <alexey.kardapoltsev@frumatic.com>" | ||
|
||
packageSummary := "Test debian package" | ||
|
||
packageDescription := """A fun package description of our software, | ||
with multiple lines.""" | ||
|
||
requiredStartFacilities in Debian := "network.target" | ||
|
||
TaskKey[Unit]("check-startup-script") <<= (target, streams) map { (target, out) => | ||
val script = IO.read(target / "debian-test-0.1.0" / "usr" / "lib" / "systemd" / "system" / "debian-test.service") | ||
assert(script.contains("Requires=network.target"), "script doesn't contain Default-Start header\n" + script) | ||
out.log.success("Successfully tested systemd start up script") | ||
() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) |
10 changes: 10 additions & 0 deletions
10
src/sbt-test/debian/systemd-deb/src/main/scala/test/Main.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package test | ||
|
||
object Main { | ||
def main (args: Array[String]) { | ||
//server app imitation | ||
while (true){ | ||
Thread.sleep(1000L) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Run the debian packaging. | ||
> debian:package-bin | ||
$ exists target/debian-test-0.1.0.deb | ||
|
||
$ exists target/debian-test-0.1.0/usr/lib/systemd/system/debian-test.service | ||
|
||
> check-startup-script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import NativePackagerKeys._ | ||
import com.typesafe.sbt.packager.archetypes.ServerLoader | ||
|
||
packageArchetype.java_server | ||
|
||
serverLoading in Rpm := ServerLoader.Systemd | ||
|
||
name := "rpm-test" | ||
|
||
version := "0.1.0" | ||
|
||
maintainer := "Alexey Kardapoltsev <alexey.kardapoltsev@frumatic.com>" | ||
|
||
packageSummary := "Test rpm package" | ||
|
||
packageDescription := """A fun package description of our software, | ||
with multiple lines.""" | ||
|
||
rpmRelease := "1" | ||
|
||
rpmVendor := "typesafe" | ||
|
||
rpmUrl := Some("http://github.com/sbt/sbt-native-packager") | ||
|
||
rpmLicense := Some("BSD") | ||
|
||
requiredStartFacilities in Rpm := "serviceA.service" | ||
|
||
TaskKey[Unit]("unzip") <<= (packageBin in Rpm, streams) map { (rpmFile, streams) => | ||
val rpmPath = Seq(rpmFile.getAbsolutePath) | ||
Process("rpm2cpio" , rpmPath) #| Process("cpio -i --make-directories") ! streams.log | ||
() | ||
} | ||
|
||
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) | ||
out.log.success("Successfully tested systemd start up script") | ||
() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) |
10 changes: 10 additions & 0 deletions
10
src/sbt-test/rpm/systemd-rpm/src/main/scala/test/Main.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package test | ||
|
||
object Main { | ||
def main (args: Array[String]) { | ||
//server app imitation | ||
while (true){ | ||
Thread.sleep(1000L) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Run the debian packaging. | ||
> rpm:packageBin | ||
$ exists target/rpm/RPMS/noarch/rpm-test-0.1.0-1.noarch.rpm | ||
|
||
> unzip | ||
$ exists usr/lib/systemd/system/rpm-test.service | ||
|
||
> checkStartupScript |