Using variables in systemd unit file

Multi tool use
Multi tool use












1















I want to use a variable in a unit file. Note, I do not want an environment variable, as I do not want the variable to be visible in the service. I just want to minimize redundancy in the unit file. eg,
I'd like to do something like:



[Service]
Type=simple
Variable=path=/usr/local/somepath
ExecStart=${path}/bin/executable -c ${path}/etc/blah.cfg


Can this be done without resorting to sh -c "path= $path/bin/executable ...." with an Environment directive?










share|improve this question























  • Short answer: you can't. Long answer: stackoverflow.com/questions/48843949/… Indeed, this question has already been answered on stackoverflow.

    – Larry
    Jan 4 at 14:47











  • It has already been answered here quite a few times. For examples: unix.stackexchange.com/questions/242019 , unix.stackexchange.com/questions/388883 , unix.stackexchange.com/questions/432129 , unix.stackexchange.com/questions/199081 , and unix.stackexchange.com/questions/216780 . No-one has yet mentioned macros, though, to my knowledge. (-:

    – JdeBP
    Jan 4 at 15:43











  • Thanks for the refs. Every question I looked at immediately started talking about environment variables, and I stopped looking too soon.

    – William Pursell
    Jan 4 at 16:09
















1















I want to use a variable in a unit file. Note, I do not want an environment variable, as I do not want the variable to be visible in the service. I just want to minimize redundancy in the unit file. eg,
I'd like to do something like:



[Service]
Type=simple
Variable=path=/usr/local/somepath
ExecStart=${path}/bin/executable -c ${path}/etc/blah.cfg


Can this be done without resorting to sh -c "path= $path/bin/executable ...." with an Environment directive?










share|improve this question























  • Short answer: you can't. Long answer: stackoverflow.com/questions/48843949/… Indeed, this question has already been answered on stackoverflow.

    – Larry
    Jan 4 at 14:47











  • It has already been answered here quite a few times. For examples: unix.stackexchange.com/questions/242019 , unix.stackexchange.com/questions/388883 , unix.stackexchange.com/questions/432129 , unix.stackexchange.com/questions/199081 , and unix.stackexchange.com/questions/216780 . No-one has yet mentioned macros, though, to my knowledge. (-:

    – JdeBP
    Jan 4 at 15:43











  • Thanks for the refs. Every question I looked at immediately started talking about environment variables, and I stopped looking too soon.

    – William Pursell
    Jan 4 at 16:09














1












1








1


1






I want to use a variable in a unit file. Note, I do not want an environment variable, as I do not want the variable to be visible in the service. I just want to minimize redundancy in the unit file. eg,
I'd like to do something like:



[Service]
Type=simple
Variable=path=/usr/local/somepath
ExecStart=${path}/bin/executable -c ${path}/etc/blah.cfg


Can this be done without resorting to sh -c "path= $path/bin/executable ...." with an Environment directive?










share|improve this question














I want to use a variable in a unit file. Note, I do not want an environment variable, as I do not want the variable to be visible in the service. I just want to minimize redundancy in the unit file. eg,
I'd like to do something like:



[Service]
Type=simple
Variable=path=/usr/local/somepath
ExecStart=${path}/bin/executable -c ${path}/etc/blah.cfg


Can this be done without resorting to sh -c "path= $path/bin/executable ...." with an Environment directive?







systemd






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 4 at 14:32









William PursellWilliam Pursell

2,18411112




2,18411112













  • Short answer: you can't. Long answer: stackoverflow.com/questions/48843949/… Indeed, this question has already been answered on stackoverflow.

    – Larry
    Jan 4 at 14:47











  • It has already been answered here quite a few times. For examples: unix.stackexchange.com/questions/242019 , unix.stackexchange.com/questions/388883 , unix.stackexchange.com/questions/432129 , unix.stackexchange.com/questions/199081 , and unix.stackexchange.com/questions/216780 . No-one has yet mentioned macros, though, to my knowledge. (-:

    – JdeBP
    Jan 4 at 15:43











  • Thanks for the refs. Every question I looked at immediately started talking about environment variables, and I stopped looking too soon.

    – William Pursell
    Jan 4 at 16:09



















  • Short answer: you can't. Long answer: stackoverflow.com/questions/48843949/… Indeed, this question has already been answered on stackoverflow.

    – Larry
    Jan 4 at 14:47











  • It has already been answered here quite a few times. For examples: unix.stackexchange.com/questions/242019 , unix.stackexchange.com/questions/388883 , unix.stackexchange.com/questions/432129 , unix.stackexchange.com/questions/199081 , and unix.stackexchange.com/questions/216780 . No-one has yet mentioned macros, though, to my knowledge. (-:

    – JdeBP
    Jan 4 at 15:43











  • Thanks for the refs. Every question I looked at immediately started talking about environment variables, and I stopped looking too soon.

    – William Pursell
    Jan 4 at 16:09

















Short answer: you can't. Long answer: stackoverflow.com/questions/48843949/… Indeed, this question has already been answered on stackoverflow.

– Larry
Jan 4 at 14:47





Short answer: you can't. Long answer: stackoverflow.com/questions/48843949/… Indeed, this question has already been answered on stackoverflow.

– Larry
Jan 4 at 14:47













It has already been answered here quite a few times. For examples: unix.stackexchange.com/questions/242019 , unix.stackexchange.com/questions/388883 , unix.stackexchange.com/questions/432129 , unix.stackexchange.com/questions/199081 , and unix.stackexchange.com/questions/216780 . No-one has yet mentioned macros, though, to my knowledge. (-:

– JdeBP
Jan 4 at 15:43





It has already been answered here quite a few times. For examples: unix.stackexchange.com/questions/242019 , unix.stackexchange.com/questions/388883 , unix.stackexchange.com/questions/432129 , unix.stackexchange.com/questions/199081 , and unix.stackexchange.com/questions/216780 . No-one has yet mentioned macros, though, to my knowledge. (-:

– JdeBP
Jan 4 at 15:43













Thanks for the refs. Every question I looked at immediately started talking about environment variables, and I stopped looking too soon.

– William Pursell
Jan 4 at 16:09





Thanks for the refs. Every question I looked at immediately started talking about environment variables, and I stopped looking too soon.

– William Pursell
Jan 4 at 16:09










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492491%2fusing-variables-in-systemd-unit-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492491%2fusing-variables-in-systemd-unit-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







nPnnoOTFeth,2xp46mBcZJEgFguuYl xXBngF2RrzusVr62k
Xtuk5rUa 0RgZ7Acoiulv3bJfrKVm08kj,NVHZ,nlUA RjWqr MK9t9Xgo3DPbT6pLI6LwUhZX7kanjgNW 87DJqlhzUgLUO45Q o

Popular posts from this blog

Scott Moir

Souastre

Biegi lekkoatletyczne