将 rpm-package 安装到 systemd?

将 rpm-package 安装到 systemd?

我是 systemd 的新手,正在尝试将内部应用程序打包为 rpm,然后安装在 systemd 主机(RHEL7)上。

rpm 尝试放置 systemd .service 文件:myapp.service 进入:/etc/systemd/系统

但这会产生错误,我不明白:

file /etc/systemd from install of myapp-0:1-.i386 conflicts with file from package systemd-219-19.el7.x86_64
file /etc/systemd/system from install of myapp-0:1-.i386 conflicts with file from package systemd-219-19.el7.x86_64  

并且安装中止。

.service文件中与安装相关的内容包括:

[Unit]
Description=MyApp
After=syslog.target network.target activemq.service
Requires=activemq.service

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
...

知道可能存在什么冲突吗?

或者如何排除故障?

编辑:从 gradle build-file 添加 rpm-stuff:

myappRpm {
    dependsOn build
    packageName 'myapp'
    arch I386
    os LINUX
    version buildVersion

    preInstall file('./deploy/rpm/preinstall')
    postInstall file('./deploy/rpm/postinstall')
    preUninstall file('./deploy/rpm/preuninstall')

    directory('/var/log/myapp', 755)
    directory('/opt/myapp/app', 755)
    directory('/opt/myapp/bin', 755)
    directory('/opt/myapp/config', 755)

    into '/opt/myapp'

    from('MyApp/build/libs/MyApp.war') {
        into '/opt/myapp/app/'
        fileMode 0755
    }

    from('deploy/systemd/myapp.sh') {
        into '/opt/myapp/bin/'
        fileMode 0755
    }

    from('deploy/systemd/myapp.env') {
        into '/opt/myapp/systemd/'
        fileMode 0755
    }

    from('deploy/systemd/myapp.service') {
        into '/etc/systemd/system/'
        fileMode 0755
    }

    doLast {
        file("$buildDir/distributions/myapp-${buildVersion}.i386.rpm").renameTo("$buildDir/distributions/myapp.rpm")
    }
}

答案1

每个 rpm 指定其安装的文件和目录列表。两个 rpm 不能安装相同的文件或目录。在您的规范文件(或者你用来描述你构建的 rpm 的任何文件)你应该不是安装/etc/systemd//etc/systemd/system/目录。在 spec 文件中;您不应该使用:

%files
/etc/systemd/

%files
/etc/systemd/system/*

(或单独指定每个文件)

编辑

寻找你的 gradle-plugin;你应该使用以下addParentDirs选项:

from('deploy/systemd/myapp.service') {
    // Will tell redline-rpm not to auto create directories, which
    // is sometimes necessary to avoid rpm directory conflicts
    addParentDirs = false
    into '/etc/systemd/system/'
    fileMode 0755
}

(看着那(这nebula-gradle-plugin github 页面上的完整使用示例了解更多信息)

相关内容