从厨师食谱客户端重新加载环境变量PATH [英] Reload environment variables PATH from chef recipes client

查看:242
本文介绍了从厨师食谱客户端重新加载环境变量PATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从厨师配方中重新加载$ ​​PATH?



我在以下线程中给出的过程信号响应中入口:



如何让厨师重新加载全球PATH



我不明白omribahumi用户给出的例子。
我想要一个更明确的例子,厨师客户/食谱了解,
与他解释,似乎有可能与该解决方法。



解决方案

我看到这个请求有两个原因:




  • 添加一些路径以立即执行=>容易,只需更新厨师运行中的ENV ['PATH']变量。


  • 扩展PATH系统以包括刚刚安装的东西。




对于2,你可能会更新/ etc / environment文件(对于ubuntu)或添加一个文件到/etc/profiled.d(更好的主意来控制它),
但显然,新的PATH变量将无法实际运行进程(包括你的实际shell),它将为文件更新后启动的进程起作用。



为了更多的解释,你给出了什么是: p>


  1. 使用导出命令创建文件t o set env variables

      echo'export MYVAR =my value'> 〜/ my_environment 


  2. 创建一个bash函数从文件加载env vars

      function reload_environment {source〜/ my_environment; 


  3. 在bash中设置一个陷阱来对信号进行某些操作,这里运行该功能bash接收SIGHUP

      trap reload_environment SIGHUP 


  4. 启动env文件首次采购的功能有两种方法:




    • easy one:启动功能

        reload_environment 


    • 复杂一个:获取实际shell的pid并发送一个SIGHUP信号

        kill -HUP`echo $$`



所有这些仅适用于当前shell,直到您将.bash_rc



正是你正在要求的,但我希望你会明白,没有办法更新已经运行的进程的上下文。



你最好的办法是:update PATH与任何你想要的方法(在/etc/profile.d为ex执行一个墙(如果厨师以root身份运行)来告诉用户重新加载它们的envs

  echo'重新加载你的shell env通过执行:source / etc / profile'|墙

再次,它可以适用于人类,而不是其他进程已经运行,那些将不得不重新启动。


is it possible to reload $PATH from a chef recipe?

Im intrsted in the response about process signals given in the following thread:

How to have Chef reload global PATH

I dont understand very well that example that the omribahumi user gives. I would like a clearer example with chef-client / recipe to understand, with that he explains, seems it is possible with that workaround.

Thanks.

解决方案

Well I see two reasons for this request:

  • add something to the path for immediate execution => easy, just update the ENV['PATH'] variable within the chef run.

  • Extend the PATH system wide to include something just installed.

For the 2, you may update /etc/environment file (for ubuntu) or add a file to /etc/profiled.d (better idea to keep control over it), But obviously the new PATH variable won't be available to actually running processes (including your actual shell), it will work for process launched after the file update.

To explain a little more the link you gave what is done is:

  1. create a file with export commands to set env variables

    echo 'export MYVAR="my value"' > ~/my_environment
    

  2. create a bash function loading env vars from a file

    function reload_environment { source ~/my_environment; }
    

  3. set a trap in bash to do something on a signal, here run the function when bash receive SIGHUP

    trap reload_environment SIGHUP
    

  4. Launch the function for a first sourcing of the env file, there's two way:

    • easy one: launch the function

      reload_environment
      

    • complex one: Get the pid of your actual shell and send it a SIGHUP signal

      kill -HUP `echo $$`
      

All of this is only for the current shell until you set this in your .bash_rc

Not exactly what you were asking for indeed, but I hope you'll understand there's no way to update context of an already running process.

The best you can do is: update the PATH with whatever method you wish (something in /etc/profile.d for exemple) and execute a wall (if chef run as root) to tell users to reload their envs

echo 'reload your shell env by executing: source /etc/profile' | wall

Once again, it could work for humans, not for other process already running, those will have to be restarted.

这篇关于从厨师食谱客户端重新加载环境变量PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆