@@ -39,8 +39,6 @@ object JavaServerAppPackaging extends AutoPlugin {
39
39
/** These settings will be provided by this archetype*/
40
40
def javaServerSettings : Seq [Setting [_]] = linuxSettings ++ debianSettings ++ rpmSettings
41
41
42
- protected def etcDefaultTemplateSource : java.net.URL = getClass.getResource(ETC_DEFAULT + " -template" )
43
-
44
42
/**
45
43
* general settings which apply to all linux server archetypes
46
44
*
@@ -59,27 +57,26 @@ object JavaServerAppPackaging extends AutoPlugin {
59
57
},
60
58
// === etc config mapping ===
61
59
bashScriptEnvConfigLocation := Some (" /etc/default/" + (packageName in Linux ).value),
62
- linuxEtcDefaultTemplate <<= sourceDirectory map { dir =>
63
- val overrideScript = dir / " templates" / ETC_DEFAULT
64
- if (overrideScript.exists) overrideScript.toURI.toURL
65
- else etcDefaultTemplateSource
66
- },
67
- linuxStartScriptName := None ,
68
- makeEtcDefault <<= (packageName in Linux , target in Universal , linuxEtcDefaultTemplate, linuxScriptReplacements)
69
- map makeEtcDefaultScript,
70
- linuxPackageMappings <++= (makeEtcDefault, bashScriptEnvConfigLocation) map { (conf, envLocation) =>
71
- val mapping = for (
72
- path <- envLocation;
73
- c <- conf
74
- ) yield LinuxPackageMapping (Seq (c -> path), LinuxFileMetaData (Users .Root , Users .Root , " 644" )).withConfig()
60
+ // (serverLoading in Rpm) apply getStartScriptLocation
75
61
76
- mapping.toSeq
77
- }
62
+ linuxStartScriptName := None
63
+ )
78
64
65
+ /* etcDefaultConfig is dependent on serverLoading (systemd, systemv, etc.),
66
+ * and is therefore distro specific. As such, these settings cannot be defined
67
+ * generally. */
68
+ private val etcDefaultConfig : Seq [Setting [_]] = Seq (
69
+ linuxEtcDefaultTemplate <<= (sourceDirectory, serverLoading)
70
+ map getEtcTemplateSource,
71
+ makeEtcDefault <<= (packageName in Linux , target in Universal , linuxEtcDefaultTemplate, linuxScriptReplacements)
72
+ map makeEtcDefaultScript,
73
+ linuxPackageMappings <++= (makeEtcDefault, bashScriptEnvConfigLocation) map
74
+ etcDefaultMapping
79
75
)
80
76
81
77
def debianSettings : Seq [Setting [_]] = {
82
78
import DebianPlugin .Names .{ Preinst , Postinst , Prerm , Postrm }
79
+ inConfig(Debian )(etcDefaultConfig) ++
83
80
inConfig(Debian )(Seq (
84
81
serverLoading := Upstart ,
85
82
startRunlevels <<= (serverLoading) apply defaultStartRunlevels,
@@ -131,6 +128,7 @@ object JavaServerAppPackaging extends AutoPlugin {
131
128
132
129
def rpmSettings : Seq [Setting [_]] = {
133
130
import RpmPlugin .Names .{ Pre , Post , Preun , Postun }
131
+ inConfig(Rpm )(etcDefaultConfig) ++
134
132
inConfig(Rpm )(Seq (
135
133
serverLoading := SystemV ,
136
134
startRunlevels <<= (serverLoading) apply defaultStartRunlevels,
@@ -242,6 +240,33 @@ object JavaServerAppPackaging extends AutoPlugin {
242
240
}
243
241
}
244
242
243
+ private [this ] def getEtcTemplateSource (sourceDirectory : File , loader : ServerLoader ): java.net.URL = {
244
+ val suffix = loader match {
245
+ case Upstart => " -upstart"
246
+ case SystemV => " -systemv"
247
+ case Systemd => " -systemd"
248
+ }
249
+
250
+ val overrides = List [File ](sourceDirectory / " templates" / (ETC_DEFAULT + suffix), sourceDirectory / " templates" / ETC_DEFAULT )
251
+ overrides.find(_.exists).map(_.toURI.toURL).getOrElse {
252
+ loader match {
253
+ case Upstart => getClass.getResource(ETC_DEFAULT + " -template" )
254
+ case SystemV => getClass.getResource(ETC_DEFAULT + " -template" )
255
+ case Systemd => getClass.getResource(ETC_DEFAULT + " -systemd-template" )
256
+ }
257
+ }
258
+ }
259
+
260
+ // Used to tell our packager to install our /etc/default/{{appName}} config file.
261
+ protected def etcDefaultMapping (conf : Option [File ], envLocation : Option [String ]): Seq [LinuxPackageMapping ] = {
262
+ val mapping = for (
263
+ path <- envLocation;
264
+ c <- conf
265
+ ) yield LinuxPackageMapping (Seq (c -> path), LinuxFileMetaData (Users .Root , Users .Root , " 644" )).withConfig()
266
+
267
+ mapping.toSeq
268
+ }
269
+
245
270
protected def startScriptMapping (name : String , script : Option [File ], loader : ServerLoader , scriptDir : String , scriptName : Option [String ]): Seq [LinuxPackageMapping ] = {
246
271
val (path, permissions, isConf) = loader match {
247
272
case Upstart => (" /etc/init/" + scriptName.getOrElse(name + " .conf" ), " 0644" , " true" )
0 commit comments