гm writing an upstart job for в service that is configured using environment переменные, and в lot of them (> 20).
The way this was handled so far was usually to run it from launcher that used Руби'с Дотенв gem to похвалите Руби the configuration file. I want to повторно нравится the launcher with в straight forward upstart file (to он уменьшает the amount of custom code I need to maintain) but I ran into the problem of how to set up all the environment переменные needed by service.
My initial take was:
script
. /etc/default/service-conf
/usr/local/bin/service
end script
but just sourcing the file doesn't export the переменные, and I don't want to add в lot of export
commands to the рукописный шрифт, mainly эксперт it will be completely unmaintainable and unreadable mess.
Существует несколько способов заняться проблемой экспорта переменных, определенных в исходном файле, включая все виды взломов (например, странное export $(cat file | xargs)
взлом зарегистрированный в этот ответ ), но самый простой способ просто включить флаг "Mark variables for export" в Вашей оболочке, прежде, чем получить файл среды.
Вот документация удара для этой функции - смотрят под -a
.
, В то время как эти script
тег в выскочке не использует Bash в качестве оболочки - это использует реализацию оболочки POSIX по умолчанию в Ubuntu, названном тире , которые также поддерживают эту функцию, называя его allexport
. Таким образом, новомодный раздел сценария должен читать:
script
set -a
. /etc/default/service-conf
/usr/local/bin/service
end script