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?
実行可能になるようにjarファイルを 'chmod'しましたか? –
はい、jarファイルのパーミッションは '755'です。これらの詳細を含めるように私の質問を改訂しました。 –