Skip to content

Commit 3fda991

Browse files
committed
Modifying the start-rpm-template and LinuxPlugin such that where the defaultLinuxLogsLocation is overridden the deamon log will be assigned to this overridden location. This was causing an issue given that the rpm would create the log location at the new location, but the daemon was still logging in the default location which was not created by the rpm. Tested on CENTOS 6.7
Added test coverage for defaultLinuxInstallLocation and defaultLinuxLogsLocation for init.d files generated upon creation of rpm
1 parent bf173d5 commit 3fda991

File tree

6 files changed

+65
-1
lines changed

6 files changed

+65
-1
lines changed

src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/systemloader/systemv/start-rpm-template

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ exec="$INSTALL_DIR/bin/${{exec}}"
4444
prog="${{app_name}}"
4545
lockfile="/var/lock/subsys/${{app_name}}"
4646

47-
RUN_CMD="$exec >> /var/log/${{app_name}}/${{rpm_daemon_log_file}} 2>&1 &"
47+
RUN_CMD="$exec >> ${{logdir}}/${{app_name}}/${{rpm_daemon_log_file}} 2>&1 &"
4848

4949
# $JAVA_OPTS used in $exec wrapper
5050
export JAVA_OPTS

src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ object LinuxPlugin extends AutoPlugin {
8080
description = (packageSummary in Linux).value,
8181
execScript = (executableScriptName in Linux).value,
8282
chdir = s"${defaultLinuxInstallLocation.value}/${(packageName in Linux).value}",
83+
logdir = defaultLinuxLogsLocation.value,
8384
appName = (packageName in Linux).value,
8485
version = sbt.Keys.version.value,
8586
daemonUser = (daemonUser in Linux).value,
@@ -155,6 +156,7 @@ object LinuxPlugin extends AutoPlugin {
155156
description: String,
156157
execScript: String,
157158
chdir: String,
159+
logdir: String,
158160
appName: String,
159161
version: String,
160162
daemonUser: String,
@@ -172,6 +174,7 @@ object LinuxPlugin extends AutoPlugin {
172174
"descr" -> description,
173175
"exec" -> execScript,
174176
"chdir" -> chdir,
177+
"logdir" -> logdir,
175178
"retries" -> retries.toString,
176179
"retryTimeout" -> retryTimeout.toString,
177180
"app_name" -> appName,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
enablePlugins(JavaServerAppPackaging)
2+
3+
name := "rpm-test"
4+
5+
version := "0.1.0"
6+
7+
maintainer := "Josh Suereth <[email protected]>"
8+
9+
packageSummary := "Test rpm package"
10+
11+
executableScriptName := "rpm-exec"
12+
13+
packageDescription := """A fun package description of our software,
14+
with multiple lines."""
15+
16+
rpmRelease := "1"
17+
18+
rpmVendor := "typesafe"
19+
20+
rpmUrl := Some("http://github.com/sbt/sbt-native-packager")
21+
22+
rpmLicense := Some("BSD")
23+
24+
defaultLinuxInstallLocation := "/opt/test"
25+
26+
defaultLinuxLogsLocation := "/opt/test/log"
27+
28+
TaskKey[Unit]("unzip") <<= (baseDirectory, packageBin in Rpm, streams) map { (baseDir, rpmFile, streams) =>
29+
val rpmPath = Seq(rpmFile.getAbsolutePath)
30+
Process("rpm2cpio" , rpmPath) #| Process("cpio -i --make-directories") ! streams.log
31+
()
32+
}
33+
34+
TaskKey[Unit]("check-init-file") <<= (baseDirectory, streams) map { (target, out) =>
35+
val initd = IO.read(target / "etc" / "init.d" / "rpm-test")
36+
assert(initd contains "/opt/test/rpm-test", "defaultLinuxInstallLocation not overriden in init.d\n" + initd)
37+
assert(initd contains "/opt/test/log/rpm-test/rpm-test.log", "defaultLinuxLogsLocation not overriden in init.d\n" + initd)
38+
out.log.success("Successfully tested rpm-test file")
39+
()
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test
2+
3+
object Main {
4+
def main (args: Array[String]) {
5+
//server app imitation
6+
while (true){
7+
Thread.sleep(1000L)
8+
}
9+
}
10+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Run the rpm packaging.
2+
> rpm:package-bin
3+
$ exists target/rpm/RPMS/noarch/rpm-test-0.1.0-1.noarch.rpm
4+
5+
> unzip
6+
$ exists opt/test/rpm-test
7+
8+
$ exists etc/init.d/rpm-test
9+
> check-init-file
10+

0 commit comments

Comments
 (0)