Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
140 views
in Technique[技术] by (71.8m points)

Read variables values from another file into a linux service unit file

I have a normal looking service file in Centos7. My execStart make a call to a shell script for the service code flow.

ExecStart = <Path to my shell script> <var1> <var2>

My requirement is, rather than sending the hardcoded values of var1, var2 etc, I want to read it from a config file and use it in my service file. The config file could look like below:

service_config.txt:
-------------------
var1 = value1
var2 = value2

I must be able to read value1 and value2 from this config inside my service file.

question from:https://stackoverflow.com/questions/65883405/read-variables-values-from-another-file-into-a-linux-service-unit-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Figured out the solution. Apologies for delayed post.

In the config file service_config.txt, enter key, values like below:

var1=value1
var2=value2

In the service unit file's service section,

[Service]
EnvironmentFile=<Absolute_path>/service_config.txt

From here on, the keys are visible using ${var1} ${var2}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...