From c957fdfcf2fc6f05cc2234eef0552f79fa7b3ab7 Mon Sep 17 00:00:00 2001 From: Justin Nichols Date: Fri, 13 Nov 2015 17:00:08 -0500 Subject: [PATCH 1/2] Support for multiple Prefix values in RPM spec. --- src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala | 2 +- .../scala/com/typesafe/sbt/packager/rpm/RpmMetadata.scala | 4 ++-- src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala | 2 +- src/sphinx/formats/rpm.rst | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala b/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala index 1528429a8..4858ce089 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala @@ -11,7 +11,7 @@ trait RpmKeys { val rpmVendor = SettingKey[String]("rpm-vendor", "Name of the vendor for this RPM.") val rpmOs = SettingKey[String]("rpm-os", "Name of the os for this RPM.") val rpmRelease = SettingKey[String]("rpm-release", "Special release number for this rpm (vs. the software).") - val rpmPrefix = SettingKey[Option[String]]("rpm-prefix", "File system prefix for relocatable package.") + val rpmPrefix = SettingKey[Seq[String]]("rpm-prefix", "File system prefix for relocatable package.") val rpmMetadata = SettingKey[RpmMetadata]("rpm-metadata", "Metadata associated with the generated RPM.") // Changelog diff --git a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmMetadata.scala b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmMetadata.scala index c6c5159b5..3131af83e 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmMetadata.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmMetadata.scala @@ -10,7 +10,7 @@ case class RpmMetadata( name: String, version: String, release: String, - prefix: Option[String] = None, + prefix: Seq[String] = Seq.empty, arch: String, vendor: String, os: String, @@ -206,7 +206,7 @@ case class RpmSpec( sb append ("Version: %s\n" format meta.version) sb append ("Release: %s\n" format meta.release) sb append ("Summary: %s\n" format meta.summary) - meta.prefix foreach { v => sb append ("prefix: %s\n" format v) } + meta.prefix foreach { v => sb append ("Prefix: %s\n" format v) } desc.license foreach { v => sb append ("License: %s\n" format v) } desc.distribution foreach { v => sb append ("Distribution: %s\n" format v) } diff --git a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala index f4d8cacf0..ce8d6ad75 100644 --- a/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala @@ -52,7 +52,7 @@ object RpmPlugin extends AutoPlugin { override lazy val projectSettings = Seq( rpmOs := "Linux", // TODO - default to something else? rpmRelease := "1", - rpmPrefix := None, + rpmPrefix := Seq.empty, rpmVendor := "", // TODO - Maybe pull in organization? rpmLicense := None, rpmDistribution := None, diff --git a/src/sphinx/formats/rpm.rst b/src/sphinx/formats/rpm.rst index 51de91890..f32e58285 100644 --- a/src/sphinx/formats/rpm.rst +++ b/src/sphinx/formats/rpm.rst @@ -232,7 +232,7 @@ Example Settings: .. code-block:: scala defaultLinuxInstallLocation := "/opt/package_root", - rpmPrefix := Some(defaultLinuxInstallLocation), + rpmPrefix ++= Seq(defaultLinuxInstallLocation), linuxPackageSymlinks := Seq.empty, defaultLinuxLogsLocation := defaultLinuxInstallLocation + "/" + name From 488ccf452b82cff0757f0c5ceabba49a659554ef Mon Sep 17 00:00:00 2001 From: Justin Nichols Date: Fri, 4 Dec 2015 09:41:30 -0500 Subject: [PATCH 2/2] Added documentation concerning the rpmPrefix --- src/sphinx/formats/rpm.rst | 39 ++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/sphinx/formats/rpm.rst b/src/sphinx/formats/rpm.rst index f32e58285..f3ad9f253 100644 --- a/src/sphinx/formats/rpm.rst +++ b/src/sphinx/formats/rpm.rst @@ -163,7 +163,7 @@ Meta Settings ~~~~~~~~~~~~~ ``rpmPrefix`` - The path passed set as the base for the revocable package + The path or paths allowed to be relocatable in the file system. ``rpmChangelogFile`` External file to be imported and used to generate the changelog of the RPM. @@ -222,20 +222,39 @@ Customize Rpm Prefix ~~~~~~~~~~ -The rpm prefix allows you to create a relocatable package as defined by http://www.rpm.org/max-rpm/s1-rpm-reloc-prefix-tag.html. -This optional setting with a handful of overrides to scriptlets and templates will allow you to create a working java_server -archetype that can be relocated in the file system. +The rpm prefix allows you to create a relocatable package as defined by http://www.rpm.org/max-rpm/s1-rpm-reloc-prefix-tag.html +and http://rpm5.org/docs/api/relocatable.html. This optional setting with a handful of overrides to scriptlets and templates +will allow you to create a working java_server archetype that can be relocated in the file system. By default, the sbt RPM +packager will create paths in the RPM spec as such: +.. code-block:: bash -Example Settings: + /usr/share/ + (packageName in Linux).value # The main application path + /var/log/ + (packageName in Linux).value # The application log path + /etc/default/ + (packageName in Linux).value # config file of the application + /var/run/ + (packageName in Linux).value # The runtime path (for PID file, etc) + /etc/init.d/ + (packageName in Linux).value # Upstart daemon file, this may also be /etc/init for a SysVinit daemon file + +The above paths, if specified in the ``rpmPrefix`` ``Seq`` list, will then allow those paths to be relocatable at the time +the RPM is being installed: .. code-block:: scala - defaultLinuxInstallLocation := "/opt/package_root", - rpmPrefix ++= Seq(defaultLinuxInstallLocation), - linuxPackageSymlinks := Seq.empty, - defaultLinuxLogsLocation := defaultLinuxInstallLocation + "/" + name - + rpmPrefix ++= Seq("/usr/share", "/var/log") + +.. code-block:: bash + + rpm -ivh output.rpm --relocate /usr/share=/opt/app/packageName/share --relocate /var/log=/opt/app/packageName/log + +One main warning to note: At the time of writing this documentation, the daemon file (``/etc/init.d/packageName`` or +``/etc/init/packageName``) will not be automatically updated to use the relocated paths because relocation occurs after +the daemon file has been written and implanted in the RPM file. This can be handled by in a number of ways: + +* Create a ``src/templates/start`` file as defined in the :ref:`Cheatsheet`. +* Use a tool like `ansible`_ (or other scripting tools like bash, sed, awk, python, ...), to alter the file post-install of the RPM. +* Instead of relocating, use a post-install tool to create symbolic links from the paths desired to the actual install paths. + +.. _ansible: http://www.ansible.com/ rpmChangelogFile ~~~~~~~~~~~~~~~~