当前位置:网站首页>Adding environment variables and templates to systemctl service
Adding environment variables and templates to systemctl service
2022-07-23 11:44:00 【Bigdata Wang Yi】
systemd.exec Chinese Manual :http://www.jinbuguo.com/systemd/systemd.exec.html#%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F
environment variable ( Reference the above connection )
Environment=
Set the environment variables of the process , Accept a space delimited VAR=VALUE list . You can use this option multiple times to add new variables or modify existing variables ( The same variable is subject to the last setting ). Set to blank to clear all previously set variables . Be careful : (1) There is no variable expansion inside the string ( That is to say "$“ No special meaning ); (2) If the value contains spaces or equal signs , You must use double quotation marks around the string (”) Definition .
for example :
Environment=“VAR1=word1 word2” VAR2=word3 “VAR3= w o r d 56 " set up Set up 了 " V A R 1 " , " V A R 2 " , " V A R 3 " 3、 ... and individual change The amount , Its value branch other by " w o r d 1 w o r d 2 " , " w o r d 3 " , " word 5 6" Set up "VAR1", "VAR2", "VAR3" Three variables , The values are "word1 word2", "word3", " word56" set up Set up 了 "VAR1","VAR2","VAR3" 3、 ... and individual change The amount , Its value branch other by "word1word2","word3","word 5 6”
Be careful , Do not use environment variables to pass confidential information to processes in the unit ( Such as passwords and passwords ). One side , Environment variables will pass D-Bus IPC Exposed to other non privileged clients ; On the other hand , Environment variables are not classified as confidential data that need to be protected in concept . Besides , Because environment variables can propagate along the process tree , And be able to cross safe boundaries ( for example setuid/setgid Program ), Therefore, confidential data may be leaked to processes that should not be accessed .
EnvironmentFile=
And Environment= similar , The difference is that this option reads the settings of environment variables from a text file . Blank lines and semicolons in the file (;) Or well number (#) The first row is ignored , The format of other lines must conform to VAR=VALUE Of shell Variable assignment syntax . Backslash at the end of the line () Will be treated as a continuation character , This is related to shell Grammatical similarity . If you want to include spaces in variable values , You must use double quotation marks at both ends of the value (") Definition .
The file must be represented by an absolute path ( You can include wildcards ). But you can add... Before the path “-” Prefix means to ignore nonexistent files . You can use this option multiple times , To read settings from multiple different files . If set to null , Means empty All environment variables that have been previously read from the file .
The files listed here will be read immediately before the process starts , Therefore, the configuration file can be generated from the previous cell , The next unit reads it .
The environment variables read from the file will overwrite Environment= Variable with the same name set in . The order in which files are read is the order in which they appear in the unit file , And for the same variable , The settings in the last read file shall prevail .
PassEnvironment=
Certain certain systemd System service manager process (PID=1) The environment variables held are passed to the processes in the unit . Accept a space separated list of variable names . You can use this option multiple times to pass more variables . If set to null , It means that all variables that have been set previously are cleared . If the variable set here is not the system service manager process (PID=1) Environment variables held , Then it will be quietly ignored . Be careful , This option is only available for passing PID=1 Of systemd Environment variables held by the system service manager process , Because the system service unit does not automatically inherit by default PID=1 Environment variables held by the process . And because the user service unit will automatically inherit by default PID≠1 Of systemd All environment variables of the user service manager process , So this option has no meaning for user service manager .
Be careful , The value of the environment variable passed through this option will be Environment= or EnvironmentFile= The variable with the same name in the option .
for example :
PassEnvironment=VAR1 VAR2 VAR3
Pass the “VAR1”, “VAR2”, “VAR3” Three variables , Its value is equal to PID=1 The value held by the process .
See environ(7) To learn more about the details of environment variables .
UnsetEnvironment=
Explicitly undo the specific environment variables of the unit . Accept a space separated variable name (“NAME”) With specific value variables (“NAME=VALUE”) list . You can use this option multiple times to undo more variables . If set to null , Then it means that all the previously set lists are cleared . Specific value variable (“NAME=VALUE”) Means only if the variable "NAME" The value of is exactly equal to "VALUE" Will be revoked "NAME" Variable . Ordinary variable names (“NAME”) It means no matter the variable "NAME" What is the value of , Will be unconditionally revoked "NAME" Variable . Be careful , because UnsetEnvironment= The undo operation of takes place in the last step before passing the environment variable to the process in the cell , So this option can undo environment variables from various channels , Include : (1) from Environment= or EnvironmentFile= Set environment variables ; (2) Environment variables inherited from the global settings of the service manager ( See systemd-system.conf(5) In the manual DefaultEnvironment= Options ); (3) according to PassEnvironment= Inherited environment variables ; (4) Environment variables set by the service manager ( for example $NOTIFY_SOCKET And so on ); (5) from PAM Environment variables set by the module ( If set PAMName= Words ).
systemctl +kylin Components demo
vi /usr/lib/systemd/system/kylin.service
adopt EnvironmentFile=/opt/bdp/kylin/kylinEnv Call environment variables
[Unit]
# The service description
Description=cosmo-bdp kylin
After=network-online.target
Requires=network-online.target
[Service]
Type=forking
# Start command
ExecStart=/bin/bash -c "JAVA_HOME=/usr/local/java exec /opt/bdp/kylin/bin/kylin.sh start"
EnvironmentFile=/opt/bdp/kylin/kylinEnv
Restart=no
RestartSec=30
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Edit the relevant environment variables of the file configuration
[[email protected] bdp]# cat /opt/bdp/kylin/kylinEnv
HADOOP_HOME=/opt/bdp/hdfs
HIVE_HOME=/opt/bdp/hive
SPARK_HOME=/opt/bdp/spark-3.1.2-bin-hadoop3.2
KYLIN_HOME=/opt/bdp/kylin
PATH=/opt/bdp/hive/bin:/opt/bdp/hdfs/sbin:/opt/bdp/hdfs/bin:/opt/bdp/spark-3.1.2-bin-hadoop3.2/bin:/opt/bdp/kylin/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] bdp]#
systemctl daemon-reload
systenctl restart kylin

边栏推荐
猜你喜欢

laravel api接口+令牌认证登录

ETH转账次数达到一个月高点

xtu-ctf Challenges-Reverse 1、2

Precautions for realizing "real-time data response" on the page

Command Execution Vulnerability and defense

编译原理-语法分析详解

Genesis provided a loan of US $2.36 billion to Sanya capital

Digital collection development / meta universe digital collection development

数仓4.0笔记——业务数据采集——Sqoop

自定义forEach标签&&select标签实现回显数据
随机推荐
NepCTF 2022 MISC <签到题>(极限套娃)
美联储理事沃勒:去中心化金融最终可能会改变传统金融市场
NFT digital collection system development, development trend of Digital Collections
DVWA学习笔记
[flick]flick on yarn's flick conf simplest configuration
MySQL account management & four engines & database and table building
window运行gradle build -- --stacktrace出现找不到文件framework-4.3.0.BUILD-SNAPSHOT-schema.zip异常
Bank of Indonesia governor said the country is actively exploring encrypted assets
shell取某一时间范围内月份
Digital collection development / digital collection system development solution
[deployment] cluster deployment and startup of presto-server-0.261.tar.gz
数仓4.0笔记——业务数据采集
XML modeling
NFT digital collection system development: Shenzhen Evening News "good times travel" digital collection online seconds chime
Entrepôt de données 4.0 Notes - acquisition de données commerciales
NFT数字藏品系统开发:深圳晚报《美好时光遨游记》数字藏品上线秒磬
数仓4.0笔记——数仓建模
Command Execution Vulnerability and defense
Phxpaxos installation and compilation process
MySQL add, delete, modify, query & advanced query statements