Change the embedded script default to disabled

Update the Maven and Gradle repackage tasks so that the embedded
startup script is no longer included by default. This change is
primarily due to the `cf` command line not currently accepting
the unusual jar format.

Fixes gh-3045
This commit is contained in:
Phillip Webb 2015-06-04 21:57:43 -07:00
parent 83300b35bf
commit 316b07d3b9
8 changed files with 162 additions and 43 deletions

View File

@ -305,10 +305,39 @@ of this guide.
[[deployment-service]]
== Installing Spring Boot applications
In additional to running Spring Boot applications using `java -jar` it is also possible
to execute applications directly on Unix systems (Linux, OSX, FreeBSD etc). This makes it
very easy to install and manage Spring Boot applications in common production
environments. As long as you are generating '`fully executable`' jars from your build, and
you are not using a custom `embeddedLaunchScript`, the following techniques can be used.
to make fully executable applications for Unix systems (Linux, OSX, FreeBSD etc).
This makes it very easy to install and manage Spring Boot applications in common
production environments. As long as you are generating '`fully executable`' jars from your
build, and you are not using a custom `embeddedLaunchScript`, the following techniques
can be used.
To create a '`fully executable`' jar with Maven use the following plugin configuration:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
----
With Gradle, the equivalent configuration would be:
[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
----
apply plugin: 'spring-boot'
springBoot {
executable = true
}
----
NOTE: Fully executable jars work by embedding an extra script at the front of the file.
Not all tools currently accept this format so you may not always be able to use this
technique.
@ -318,9 +347,9 @@ or `systemd`.
==== Installation as a init.d (System V) service
The default executable script that is embedded into Spring Boot executable jars will act
as an `init.d` script when it is symlinked to `/etc/init.d`. The standard `start`, `stop`,
==== Installation as a init.d service (System V)
The default executable script that can be embedded into Spring Boot jars will act as an
`init.d` script when it is symlinked to `/etc/init.d`. The standard `start`, `stop`,
`restart` and `status` commands can be used. The script supports the following features:
* Starts the services as the user that owns the jar file
@ -349,7 +378,32 @@ if you use Debian:
=== Running a JAR as a regular (not service) script
==== Installation as a systemd service
Systemd is the successor to `init.d` scripts, and now being used by many many modern Linux
distributions. Although you can continue to use `init.d` script with `systemd`, it is also
possible to launch Spring Boot applications using `systemd` '`service`' scripts.
For example, to run a Spring Boot application installed in `var/myapp` you can add the
following script in `/etc/systemd/system/myapp.service`:
[indent=0]
----
[Unit]
Description=myapp
After=syslog.target
[Service]
ExecStart=/var/myapp/myapp.jar
[Install]
WantedBy=multi-user.target
----
TIP: Remember to change the `Description` and `ExecStart` fields for your application.
==== Customizing the startup script
The script accepts the following parameters as environment variables, so you can change
the default behavior in a script or on the command line:
@ -358,11 +412,11 @@ the default behavior in a script or on the command line:
|Variable |Description
|`MODE`
|The "mode" of operation. The default depends on the way the jar was built, but will
usually be "auto" (meaning it tries to guess if it is an init script by checking if it
is a symlink in a directory called "init.d"). You can explicitly set it to "service" so
that the "stop|start|status|restart" commands work, or to "run" if you just want to run
the script and not in the background.
|The "`mode`" of operation. The default depends on the way the jar was built, but will
usually be `auto` _(meaning it tries to guess if it is an init script by checking if it
is a symlink in a directory called `init.d`)_. You can explicitly set it to `service` so
that the `stop\|start\|status\|restart` commands work, or to `run` if you just want to
run the script in the foreground.
|`PID_FOLDER`
|The root name of the pid folder (`/var/run` by default).
@ -390,31 +444,6 @@ the default behavior in a script or on the command line:
==== Installation as a systemd service
Systemd is the successor to `init.d` scripts, and now being used by many many modern Linux
distributions. Although you can continue to use `init.d` script with `systemd`, it is also
possible to launch Spring Boot applications using `systemd` '`service`' scripts.
For example, to run a Spring Boot application installed in `var/myapp` you can add the
following script in `/etc/systemd/system/myapp.service`:
[indent=0]
----
[Unit]
Description=myapp
After=syslog.target
[Service]
ExecStart=/var/myapp/myapp.jar
[Install]
WantedBy=multi-user.target
----
TIP: Remember to change the `Description` and `ExecStart` fields for your application.
[[deployment-whats-next]]
== What to read next
Check out the http://www.cloudfoundry.com/[Cloud Foundry], https://www.heroku.com/[Heroku]

View File

@ -137,7 +137,7 @@ public class SpringBootPluginExtension {
* If a fully executable jar (for *nix machines) should be generated by prepending a
* launch script to the jar.
*/
boolean executable = true;
boolean executable = false;
/**
* The embedded launch script to prepend to the front of the jar if it is fully

View File

@ -210,7 +210,8 @@ public class RepackageTask extends DefaultTask {
}
private LaunchScript getLaunchScript() throws IOException {
if (this.extension.isExecutable()) {
if (this.extension.isExecutable()
|| extension.getEmbeddedLaunchScript() != null) {
return new DefaultLaunchScript(this.extension.getEmbeddedLaunchScript(),
this.extension.getEmbeddedLaunchScriptProperties());
}

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.boot.maven.it</groupId>
<artifactId>jar-executable</artifactId>
<version>0.0.1.BUILD-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<executable>true</executable>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>some.random.Main</mainClass>
</manifest>
<manifestEntries>
<Not-Used>Foo</Not-Used>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>@spring.version@</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>@servlet-api.version@</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,24 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.test;
public class SampleApplication {
public static void main(String[] args) {
}
}

View File

@ -0,0 +1,7 @@
import java.io.*;
import org.springframework.boot.maven.*;
Verify.verifyJar(
new File( basedir, "target/jar-executable-0.0.1.BUILD-SNAPSHOT.jar" ), "some.random.Main", "Spring Boot Startup Script"
);

View File

@ -2,6 +2,6 @@ import java.io.*;
import org.springframework.boot.maven.*;
Verify.verifyJar(
new File( basedir, "target/jar-0.0.1.BUILD-SNAPSHOT.jar" ), "some.random.Main", "Spring Boot Startup Script"
new File( basedir, "target/jar-0.0.1.BUILD-SNAPSHOT.jar" ), "some.random.Main"
);

View File

@ -132,7 +132,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
* jar.
* @since 1.3
*/
@Parameter(defaultValue = "true")
@Parameter(defaultValue = "false")
private boolean executable;
/**
@ -218,7 +218,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
}
private LaunchScript getLaunchScript() throws IOException {
if (this.executable) {
if (this.executable || this.embeddedLaunchScript != null) {
return new DefaultLaunchScript(this.embeddedLaunchScript,
this.embeddedLaunchScriptProperties);
}