如何从Java Gradle项目中获取deb包,安装deb文件后会自动生成 /etc/systemd/system/project.service ,并在 /中添加二进制文件var / project / bin / ,以及 / etc / project / 中的配置文件 像https://github.com/nebula-plugins/gradle-ospackage-plugin之类的东西,但有systemd支持。 抱歉英文不好!
答案 0 :(得分:2)
我发现我可以使用提到的nebula-plugin 我只需要将这些行添加到 build.gradle 文件:
buildDeb {
link('/etc/systemd/system/project.service', '/opt/project/bin/project.service')
}
并创建一个 project.service 文件,如下所示,并使插件将服务文件移动到deb软件包的安装目录:
[Unit]
Description=<description>
[Service]
User=<user>
Group=<group>
EnvironmentFile=-/etc/default/project
ExecStart=/opt/project/bin/project > /var/log/project/project.log
Restart=no
[Install]
WantedBy=multi-user.target
下面的代码将服务文件(如果你把它放在项目根目录的bin目录中)和所有其他必要的文件来安装deb文件的目录:
ospackage {
packageName = 'project'
configurationFile "/opt/project/bin/project.service"
into '/opt/project'
from(jar.outputs.files) {
into 'lib'
}
from(configurations.runtime) {
into 'lib'
}
from('build/libs') {
into 'lib'
}
from('conf'){
into 'conf'
}
from('bin') { //project.service is in bin directory
fileType = CONFIG | NOREPLACE //wont replace any configurationFile in this directory
into 'bin'
}
from('build/scripts') {
into 'bin'
exclude 'database'
fileMode = 0550
}
}