Chef:设置环境变量

时间:2017-03-07 10:00:18

标签: chef

我需要在Centos / 7机器上设置OS环境变量。

我已在我的variables.rb文件中尝试使用它:

host = 'locahost'
port = 9201

ENV['LV_ES_HOST'] = host
ENV['LV_ES_PORT'] = '#{port}'

然而,在shell上:

$ echo $LV_ES_HOST

$
  1. 我如何设置Os环境变量?
  2. 是否可以设置仅对用户可见的OS环境变量?
  3. 我需要一个OS可用的环境变量,以便我的jee应用程序能够读取它的值。

    我在我的机器上运行了几个jee容器,并且正在运行的应用程序需要获取LC_ES_HOST环境变量。

1 个答案:

答案 0 :(得分:2)

另一个问题并没有真正解释潜在的问题。在import cv2 print ('Press [ESC] to quit demo') # Read from the input video file # input_file = 'Your path to input video file' # camera = cv2.VideoCapture(input_file) # Or read from your computer camera camera = cv2.VideoCapture(0) # Output video file may be with another extension, but I didn't try # output_file = 'Your path to output video file' + '.avi' output_file = "out.avi" # 4-byte code of the video codec may be another, but I did not try fourcc = cv2.VideoWriter_fourcc(*'DIVX') is_begin = True while camera.isOpened(): _, frame = camera.read() if frame is None: break # Your code processed = frame if is_begin: # Right values of high and width h, w, _ = processed.shape out = cv2.VideoWriter(output_file, fourcc, 30, (w, h), True) print(out.isOpened()) # To check that you opened VideoWriter is_begin = False out.write(processed) cv2.imshow('', processed) choice = cv2.waitKey(1) if choice == 27: break camera.release() out.release() cv2.destroyAllWindows() 期间,Unix环境变量从父进程继承到子进程。因此,当您在Chef代码中通过fork()设置内容时,它会影响Chef下的子进程,就像通过ENV资源运行的东西一样。但是,当您通过SSH登录时,您的shell不是execute的子进程,因此这些变量不可见。不幸的是,Unix没有针对全局环境变量的通用解决方案,所以你需要选择一个妥协中的一个,这些妥协在另一个问题中列出。