如何通过 systemd EnvironmentFile 传递数组?

如何通过 systemd EnvironmentFile 传递数组?
[root@vm-devcjn-01-a tmp]# cat /tmp/test_service_script_fred
#!/bin/bash

sleep 30&
echo `date` $# args: $@ > $0.log

当从 shell 调用时,传递一个数组,按预期工作:

[root@vm-devcjn-01-a tmp]# args=("THIS" "THAT" "123456")
[root@vm-devcjn-01-a tmp]# ./test_service_script_fred  ${args[@]}
[root@vm-devcjn-01-a tmp]# tail test_service_script_fred.log
Wed 18 Oct 19:36:51 BST 2023 3 args: THIS THAT 123456

但是,当通过 systemd 服务调用时,使用通过 EnvironmentFile 传递的相同数组,它不会:

[root@vm-devcjn-01-a tmp]# cat StartArgs
args=("THIS" "THAT" "123456")

[root@vm-devcjn-01-a tmp]# systemctl cat test@fred
# /etc/systemd/system/[email protected]
# The test service unit template file
#
# version=$Header

[Unit]
Description=test %I instance

[Service]
Type=forking
KillMode=process
WorkingDirectory=/tmp
EnvironmentFile=/tmp/StartArgs
ExecStart=/bin/bash /tmp/test_service_script_%i ${args[@]}

[root@vm-devcjn-01-a tmp]# systemctl start test@fred
[root@vm-devcjn-01-a tmp]# tail test_service_script_fred.log
Wed 18 Oct 19:39:12 BST 2023 1 args:

相关内容