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

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

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大