在ubuntu中以service方式运行symfony命令


run symfony command as service in ubuntu

我有一个在终端正常运行的命令:

 php -f /home/roshd-user/Symfony/app/console video:convert

我想在我的服务器上运行这个命令作为服务。在/etc/init/中创建一个vconverter .conf文件。

这个服务正常运行(启动和停止),但不执行我的命令?

我的命令没有服务运行良好,返回我的结果,但当使用它到一个服务不执行?!

vconverter .conf包含以下代码:

#info
description "Video Convertor PHP Worker"
author      "Netroshd"
# Events
start on startup
stop on shutdown
# Automatically respawn
respawn
respawn limit 20 5
# Run the script!
# Note, in this example, if your PHP script returns
# the string "ERROR", the daemon will stop itself.
script
    [ $( exec php -f /home/roshd-user/Symfony/app/console video:convert
 ) = 'ERROR' ] && ( stop; exit 1; )
end script

我将在配置中声明setuidsetgid为Apache用户组,即www-data并使您的命令在prod Symfony环境中运行。

#info
description "Video Convertor PHP Worker"
author      "Netroshd"
# Events
start on startup
stop on shutdown
# Automatically respawn
respawn
respawn limit 20 5
# Run as the www-data user and group (same as Apache is under in Ubuntu)
setuid www-data
setgid www-data
# Run the script!
exec php /home/roshd-user/Symfony/app/console video:convert -e prod --no-debug -q

如果你仍然有问题,它可能值得安装"wrep/daemonizable-command"与作曲家和使您的视频转换命令扩展Wrep'Daemonizable'Command'EndlessContainerAwareCommand。该库还提供了如何使用它的示例