Search code examples
scalarpmrpmbuildplayframework-2.4sbt-native-packager

Add custom scripts for RPM package for a Play scala project


I would like to add a few commands to the RPM package (built using sbt-native-packager) for a Play scala project. For example:

mkdir -p /opt/myapp
chmod +w /opt/myapp

so that they can be executed when installing the RPM package via yum.

I saw in a standard sbt project, looks like we could use custom template:

src/templates/start

but in a Play project, we have the following folders:

app
conf
project
dist

where we don't have src folder at all.

I would like to know how to add custom commands which can be run before or after installing RPM for a Play project.


Solution

  • I haven't used this functionality of the sbt-native-packager, but I do know that RPM spec files support defining scripts that run in specific events (e.g. %pre - runs just before install).

    It looks like sbt-native-package supports this by overriding the maintainerScripts:

    // overriding
    import RpmConstants._
    maintainerScripts in Rpm := Map(
      Pre -> Seq("""echo "pre-install""""),
      Post -> Seq("""echo "post-install""""),
      Pretrans -> Seq("""echo "pretrans""""),
      Posttrans -> Seq("""echo "posttrans""""),
      Preun -> Seq("""echo "pre-uninstall""""),
      Postun -> Seq("""echo "post-uninstall"""")
    )
    

    Please note this is only available from 1.1.0+ of sbt-native-package.

    There are a couple of other approaches which are detailed in the documentation