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

边栏推荐
- Bank of Indonesia governor said the country is actively exploring encrypted assets
- Es operation command
- Customize foreach tags & select tags to echo data
- 通用查询&分页代码
- php+码云 代码钩子自动更新线上代码
- sql实现连续登陆7天以上用户统计
- General Query & paging code
- Federal Reserve governor Waller: decentralized finance may eventually change the traditional financial market
- NFT数字藏品平台开发搭建,源码开发数字藏品
- [pyautogui learning] screen coordinates and mouse scrolling
猜你喜欢

Nepctf 2022 misc < check in question > (extreme doll)

DVWA学习笔记

CTF-web 常用软件安装及环境搭建

NFT digital collection development: what are the possible application scenarios of digital collections in the future?

Compilation principle - detailed explanation of syntax analysis

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

Preliminary study on DC-1 shooting range
![[doris] configure and basically use the contents system (continue to add content when you have time)](/img/74/21c5c0866ed6b1bb6f9a1e3755b61e.png)
[doris] configure and basically use the contents system (continue to add content when you have time)

MySQL之账号管理&&四大引擎&&建库建表

Flex+js realizes that the height of the internal box follows the maximum height
随机推荐
Sqli lab 1-16 notes with customs clearance
编译原理-语法分析详解
[pyautogui learning] screen coordinates and mouse scrolling
php+码云 代码钩子自动更新线上代码
xtu-ctf Challenges-Reverse 1、2
Security problems of FileInfo in PHP file upload
Command Execution Vulnerability and defense
自定义MVC(上)
composer的一些操作
Points for attention when using El table to lazy load tree tables
Data warehouse 4.0 notes - user behavior data collection III
数字藏品系统开发:NFT的主要特点有哪些?
Dynamically set the theme color of the card
mysqldump批量导出mysql建表语句
数字藏品系统开发/数字藏品方案介绍
用户连续登陆(允许中断)查询sql
[hudi]hudi compilation and simple use of Hudi & spark and Hudi & Flink
NFT digital collection system development, development trend of Digital Collections
Flex+js realizes that the height of the internal box follows the maximum height
Nepctf 2022 misc < check in question > (extreme doll)