2016-11-29 6 views
2

systemdがサービスとして直接実行できるSpringブートjarファイルを作成するにはどうすればよいですか?systemdがサービスとして直接実行できるSpringブートjarファイルを作成するにはどうすればよいですか?

Installation as a systemd serviceの例に続いて、私は直接、春のブートjarファイル実行次にsystemdサービスを作成:このサービスを開始するとき

[Unit] 
Description=CRS Self-certification Service 
Documentation= 
Requires=postgresql.service 
After=postgresql.service 

[Service] 
Environment=LOADER_PATH='lib/,config/,/etc/opes/crs/selfcertification' 
ExecStart=/opt/opes/crs/selfcertification/crs-selfcertification-1.0.0-SNAPSHOT.jar 
Restart=always 
RestartSec=10 
User=crs 

[Install] 
WantedBy=multi-user.target 

をしかし、systemdには、jarファイルが実行可能ではないと文句を言い:

jarファイルの
Nov 29 10:57:59 ubuntu systemd[24109]: selfcertification.service: Failed at step EXEC spawning /opt/opes/crs/selfcertification/crs-selfcertification-1.0.0-SNAPSHOT.jar: Exec format error 
Nov 29 10:57:59 ubuntu systemd[1]: selfcertification.service: Main process exited, code=exited, status=203/EXEC 
Nov 29 10:57:59 ubuntu systemd[1]: selfcertification.service: Unit entered failed state. 
Nov 29 10:57:59 ubuntu systemd[1]: selfcertification.service: Failed with result 'exit-code'. 

権限が755(全てによって実行可能)である。

systemdサービス用の実行可能なjarファイルをビルドするには、次のGradleビルドスクリプトにどのような変更を加える必要がありますか?

buildscript { 
    ext { 
     springBootVersion = '1.4.2.RELEASE' 
    } 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'org.springframework.boot' 

jar { 
    baseName = 'crs-selfcertification' 
    version = '1.0.0-SNAPSHOT' 
} 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

repositories { 
    mavenCentral() 
} 

springBoot { 
    mainClass = "com.opessoftware.crs.selfcertification.Application" 
    layout = "ZIP" 
} 

dependencies { 
    compile("org.springframework.boot:spring-boot-starter-web") 
    compile("org.springframework.boot:spring-boot-starter-thymeleaf") 
    compile("org.springframework.boot:spring-boot-starter-data-jpa") 
    compile("org.springframework.boot:spring-boot-starter-mail") 
    testCompile("org.springframework.boot:spring-boot-starter-test") 
    compile group: 'org.postgresql', name: 'postgresql', version: '9.4.1208.jre7' 
    compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.1.1' 
    compile group: 'junit', name: 'junit', version: '4.12' 

} 

(注)このサービスは正常に動作することを代わりには、シェルスクリプトからJava仮想マシン(JVM)を使用して、それを起動する代わりにsystemd、直接jarファイルを実行しようとしているのであれば:

[Unit] 
Description=CRS Self-certification Service 
Documentation= 
Requires=postgresql.service 
After=postgresql.service 

[Service] 
Environment=LOADER_PATH='lib/,config/,/etc/opes/crs/selfcertification' 
#ExecStart=/opt/opes/crs/selfcertification/crs-selfcertification-1.0.0-SNAPSHOT.jar 
ExecStart=/opt/opes/crs/selfcertification/startCrsSelfCertification 
Restart=always 
RestartSec=10 
User=crs 

[Install] 
WantedBy=multi-user.target 

シェルスクリプト/opt/opes/crs/selfcertification/startCrsSelfCertificationは、JVMを使用してjarファイルを起動します:

#!/bin/sh 

java -Dloader.path='lib/,config/,/etc/opes/crs/selfcertification' -jar /opt/opes/crs/selfcertification/crs-selfcertification-1.0.0-SNAPSHOT.jar 

春ボーから欠落している可能性がありますどのようなsystemdがjarファイルを直接実行できないようにするjarfile?

+0

実行可能になるようにjarファイルを 'chmod'しましたか? –

+0

はい、jarファイルのパーミッションは '755'です。これらの詳細を含めるように私の質問を改訂しました。 –

答えて

2

あなたは完全に実行可能フォームにご希望のプロジェクトを再パッケージ化する春ブーツを指示する必要があります。

springBoot { 
    executable = true 
} 

と、この機能は春ブーツ1.4.0+でのみ使用可能です。

詳細については、http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html#build-tool-plugins-gradle-repackage-configurationを参照してください。

+0

ボーナスポイントについては、実行可能なJARのJVMパラメータをどのように変更するのですか?たとえば、最大ヒープサイズ「-Xmx2048m」を設定するにはどうすればよいですか? –

+1

'your-app.conf'を' JAVA_OPTS = -Xmx2048M'という内容の 'your-app.jar'の隣に置きます。[deployment script customization](https://github.com/spring-projects/spring-boot)を参照してください。 /blob/master/spring-boot-docs/src/main/asciidoc/deployment.adoc#deployment-script-customization-conf-file)guideまたは[launch.script](https://github.com/spring-projects) /spring-boot/blob/master/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script)を参照してください。 – tan9

+0

more pointについてはhttp://stackoverflow.com/q/40893530/107158を参照してください。 –

関連する問題