Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates RPM规范中模板化的.service/.conf文件的建议_Templates_Service_Rpm_Rpm Spec - Fatal编程技术网

Templates RPM规范中模板化的.service/.conf文件的建议

Templates RPM规范中模板化的.service/.conf文件的建议,templates,service,rpm,rpm-spec,Templates,Service,Rpm,Rpm Spec,我们已经从.spec文件创建了RPM,这些文件包括upstart和systemd(因此,.conf和.service)文件的服务安装。但是.conf和.service文件包含指向服务文件的硬连线路径 myservice.service: [Unit] Description=My Service [Service] WorkingDirectory=/opt/myproduct ExecStart=/opt/myproduct/myservice /opt/myproduct/myservic

我们已经从.spec文件创建了RPM,这些文件包括upstart和systemd(因此,.conf和.service)文件的服务安装。但是.conf和.service文件包含指向服务文件的硬连线路径

myservice.service:

[Unit]
Description=My Service

[Service]
WorkingDirectory=/opt/myproduct
ExecStart=/opt/myproduct/myservice /opt/myproduct/myservicearg
Restart=always

[Install]
WantedBy=multi-user.target
myservice.conf:

description "My Service"

respawn
respawn limit 15 5

start on (stopped rc and runlevel [2345])
stop on runlevel [06]

chdir /opt/myproduct

exec /opt/myproduct/myservice /opt/myproduct/myservicearg
安装路径可能会改变,但暴力搜索和替换似乎是石器时代的事情

我已经将Ansible与.j2(Jinja2)模板文件一起使用,这似乎是在二进制/脚本路径中使用变量的好方法。使用它们可能看起来像这样:

myservice.service.j2:

[Unit]
Description=My Service

[Service]
WorkingDirectory={{ myproductpath }}
ExecStart={{ myproductpath }}/myservice {{ myproductpath }}/myservicearg
Restart=always

[Install]
WantedBy=multi-user.target
myservice.conf.j2:

description "My Service"

respawn
respawn limit 15 5

start on (stopped rc and runlevel [2345])
stop on runlevel [06]

chdir {{ myproductpath }}

exec {{ myproductpath }}/myservice {{ myproductpath }}/myservicearg

但我找不到任何证据表明这是构建RPM的常用方法。RPM中是否有一种推荐的方法来模板化这些.conf和.service文件(在RPM构建或安装期间填写)?

否。RPM没有任何此类模板化工具。大多数开发人员更喜欢经典的sed:

%build
....
sed -i 's/{{ myproductpath }}/\/real\/path/g' myservice.conf.j2
mv myservice.conf.j2 myservice.conf
或者您可以
BuildRequires:ansible
并让ansible对其进行扩展。但对于这项工作来说,这是一个相当沉重的工具