当前位置:网站首页>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

边栏推荐
- mysqldump批量导出mysql建表语句
- Data warehouse 4.0 notes - Data Warehouse Modeling
- Dynamically set the theme color of the card
- NFT数字藏品开发:京东“奇达熊带你游京城”旅游套装
- Development of digital collection system: enterprise layout meta universe digital collection
- Scala之二流程控制
- Custom formula input box
- NFT数字藏品系统开发,数字藏品的发展趋势
- 数仓4.0笔记——业务数据采集——Sqoop
- DVWA learning notes
猜你喜欢

NFT digital collection system development: Shenzhen Evening News "good times travel" digital collection online seconds chime

NepCTF 2022 MISC <签到题>(极限套娃)

DC-1靶场初探

数字藏品开发/元宇宙数字藏品开发

Security problems of FileInfo in PHP file upload

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

NFT数字藏品开发/DAPP开发

MySQL password free login settings

第六届“蓝帽杯”全国大学生网络安全技能大赛-初赛Writeup

自定义forEach标签&&select标签实现回显数据
随机推荐
Customize foreach tags & select tags to echo data
Goodbye if else
NFT digital collection platform development and construction, source code development digital collection
数字藏品系统开发:NFT的主要特点有哪些?
Two sorting and one random data fetching of stored procedures
window下vmware使用无线网卡nat的方式上网
Laravel API interface + token authentication login
mysql根据中文字段首字母排序
sql实现连续登陆7天以上用户统计
ES操作命令
Data warehouse 4.0 notes - user behavior data collection III
自定义MVC的使用&增删改查
Data warehouse 4.0 notes - Data Warehouse Modeling
數倉4.0筆記——業務數據采集
Phxpaxos installation and compilation process
印尼央行行长称该国正在积极探索加密资产
Federal Reserve governor Waller: decentralized finance may eventually change the traditional financial market
Entrepôt de données 4.0 Notes - acquisition de données commerciales
Solve the problem that the time format of manually querying Oracle database is incorrect (date type)
Mysqldump batch export MySQL table creation statement