应用示例
概述
参考:
开机建立远程隧道
[Unit]
Description=Remote SSH
[Service]
ExecStart=/bin/ssh -N -R 20001:localhost:22 root@10.253.26.241
Restart=on-failure
RestartSec=10
[Install]
WantedBy=network.target
让 Service 使用环境变量
[Unit]
Description=UnitDemo
[Service]
EnvironmentFile=/etc/default/demo
ExecStart=/usr/local/bin/unit-demo.sh
[Install]
WantedBy=multi-user.target
~]# cat /etc/default/demo
DEMO=DesistDaydream
~]# cat /usr/local/bin/unit-demo.sh
#!/bin/bash
#
while :
do
echo $DEMO
sleep 5
done
启动 Service 后,可以看到如下输出
Aug 01 14:14:45 centos7-2009 systemd[1]: Started Foo.
Aug 01 14:14:45 centos7-2009 unit-demo.sh[8901]: DesistDaydream
Aug 01 14:14:50 centos7-2009 unit-demo.sh[8901]: DesistDaydream
Aug 01 14:14:55 centos7-2009 unit-demo.sh[8901]: DesistDaydream
Aug 01 14:15:00 centos7-2009 unit-demo.sh[8901]: DesistDaydream
反馈
此页是否对你有帮助?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.