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 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用