在centos7中作为systemd服务运行php脚本
我正在尝试在centos7启动时运行phpscript。当前systemd进程如下所示在centos7中作为systemd服务运行php脚本,php,centos7,systemd,Php,Centos7,Systemd,我正在尝试在centos7启动时运行phpscript。当前systemd进程如下所示 [Unit] Description=custom Service After=network.target [Service] Type=forking User=root ExecStart=/usr/bin/php /var/www/htdocs/mysite/public/index.php abc xyz >> /var/log/custom.log 2>&1 [I
[Unit]
Description=custom Service
After=network.target
[Service]
Type=forking
User=root
ExecStart=/usr/bin/php /var/www/htdocs/mysite/public/index.php abc xyz >> /var/log/custom.log 2>&1
[Install]
WantedBy=multi-user.target
但上面的脚本并没有传递参数。我如何解决这个问题?谢谢 尝试一下这种配置
[Service]
Type=forking
User=root
PHP_PARAM_1=abc
PHP_PARAM_2=xyz
ExecStart=/usr/bin/php /var/www/htdocs/mysite/public/index.php $PHP_PARAM_1 $PHP_PARAM_2>> /var/log/custom.log 2>&1
更新
[Service]
Type=forking
User=root
Environment="abc xyz"
ExecStart=/usr/bin/php /var/www/htdocs/mysite/public/index.php $PHP_PARAM_1 $PHP_PARAM_2>> /var/log/custom.log 2>&1
另外,我创建了一个
myphp.sh
bash脚本
#!/bin/bash
nohup /usr/bin/php /var/www/htdocs/mysite/public/index.php abc xyz & >> /var/log/custom.log 2>&1
然后在systemd脚本中
[Unit]
Description=custom Service
After=network.target
[Service]
Type=forking
User=root
ExecStart=/etc/init.d/myphp.sh
[Install]
WantedBy=multi-user.target
将这些参数作为正常参数o_o
var_dump($argv)传递代码>这将帮助我们更好地理解您所说的正常参数是什么?从linux命令行执行/usr/bin/php/var/www/htdocs/mysite/public/index.php abc xyz的工作与预期一样。只有systemd脚本不起作用。ExecStart
不支持重定向等shell功能。它将被传递到execve()
,它只是一个程序路径和一个参数列表,由空格分隔。这就是为什么这不起作用。