小编ele*_*eek的帖子

如何在“systemd”服务文件中获取机器 IP 地址

我需要获取机器的 IP 并在我的服务中使用它:

[Unit]
Description=Redmine server
After=syslog.target
After=network.target

[Service]
Type=simple
User=redmine
Group=redmine
ip="$(/sbin/ip -o -4 addr list eno16777736 | awk '{print $4}' | cut -d/ -f1)"
ExecStart=/usr/bin/ruby /home/redmine/redmine/bin/rails server webrick -e production -b $ip -p 3000

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

如何在systemd服务文件中执行此命令并获取其结果:

ip=$(/sbin/ip -o -4 addr list eno16777736 | awk '{print $4}' | cut -d/ -f1)
Run Code Online (Sandbox Code Playgroud)

为了使用它的结果 infor xxx.xxx.xxx.xxx,像这样:

ExecStart=/usr/bin/ruby /home/redmine/redmine/bin/rails server webrick -e production …
Run Code Online (Sandbox Code Playgroud)

bash systemd centos-7

12
推荐指数
3
解决办法
2万
查看次数

标签 统计

bash ×1

centos-7 ×1

systemd ×1