doutuan9357 2017-04-19 12:02 采纳率: 100%
浏览 80
已采纳

CloudFoundry容器安装linux邮件命令

While porting a PHP/Wordpress application to CloudFoundry, we are facing the issue that the application relies on the linux mail command, which is not installed on CloudFoundry containers by default.

Is there a way of getting this installed within the container the apps runs on upon startup?

  • 写回答

1条回答 默认 最新

  • dreamfly0514 2017-04-20 11:58
    关注

    The best solution is to transition your app to talking directly to an SMTP server. There are Wordpress plugins that will let you do this. You might want to consider utilizing one of them. I don't know your situation, but using them is often straightforward.

    If that's not an option, you basically need to package a mail binary or script with your app. You can then either point Wordpress to that executable directly or you can adjust the PATH environment variable so the binary is on your path and Wordpress can find it.

    A couple notes on this:

    1. You can't install RPM or DEB packages because you can't get root access on CF. The best you can do is to bring your own binaries and scripts with the application (or write a custom build pack, but that's a lot more work).

    2. You might be able to take the mail binary from a Linux system and bundle it with your app. For example, install mail in a VM (running Ubuntu Trusty or use the cloudfoundry/cflinuxfs2 docker image), copy the mail binary and dependent shared libraries to a directory in your application. Push your app including those binaries. You can then adjust the PATH and LD_LIBRARY_PATH env variables so that Wordpress can find the command and the command can find it's associated shared libraries.

    3. If you can't / don't want to mess with #2, you could write a script in your favorite scripting language (Python, Perl, Ruby, PHP, etc..) that implements a similar cli as the mail command (just enough to satisfy the needs of Wordpress) and talks directly to an SMTP server. Name the script mail and point Wordpress to it or put in on the PATH.

    4. To adjust the PATH environment variable, you don't want to use cf set-env. That's because you can only override variables with cf set-env, you can't do the traditional PATH=$PATH:/my/new/path. To make this work, you want to include a .profile file in the root of your application. This will be picked up and sourced prior to your application starting and in it you can add PATH=$PATH:$HOME/path/to/mail/script, where /path/to/mail/script is the location of what you are bundling with your application and what you want available on the path. We prefix that with $HOME so that it points to our application.

      https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何构建全国统一的物流管理平台?
  • ¥100 ijkplayer使用AndroidStudio/CMake编译,如何支持 rtsp 直播流?
  • ¥20 和学习数据的传参方式,选择正确的传参方式有关
  • ¥15 这是网络安全里面的poem code
  • ¥15 用js遍历数据并对非空元素添加css样式
  • ¥15 使用autodl云训练,希望有直接运行的代码(关键词-数据集)
  • ¥50 python写segy数据出错
  • ¥20 关于线性结构的问题:希望能从头到尾完整地帮我改一下,困扰我很久了
  • ¥30 3D多模态医疗数据集-视觉问答
  • ¥20 设计一个二极管稳压值检测电路