ubuntu18.04 Yii2.0 安装yii2-queue并在Linux启动守护进程监听消息设置

三、Linux systemd介绍

systemd是linux下的一款系统和服务管理器,为什么要使用systemd ? 在rpm包二进制方式安装的linux软件中,使用init守护进程进行服务状态的管理或者使用service命令 例如启动Mysql数据库可以是 /etc/init.d/mysql start 或者service mysql start.

使用linux init进程进行管理服务的时候有两个缺点:

  1.init系统进程是串行执行的,也就是同步的 ,只有前一个进程启动完成,才会启动下一进程。

  2.启动脚步复杂,init进程是只执行启动脚步,不管其他的任务

使用Systemd优点:

  1.Systemd支持并行化任务,

  2.同时采用socket于D-Bus总线式激活服务,按需启动守护进程(daemon)

在新版的Linux系统中都在使用sytemd 进行管理 例如(Ubuntu 18、Ubuntu 16、Debian 8、CentOS 7)

四、在Linux创建systemd系统服务监听队列消息

1、在Linux下进入system目录,相关命令:cd /etc/systemd/system;

2、新增yii-queue@.service文件,相关命令:vi yii-queue.service;

3、yii-queue.service文件内容如下:

[Unit]
Description=Yii Queue Worker %I
After=network.target
# the following two lines only apply if your queue backend is mysql
# replace this with the service that powers your backend
# After=mysql.service
# Requires=mysql.service

[Service]
Type=notify
ExecStart=/usr/bin/php /var/www/html/edc/yii queue/listen --verbose
Restart=on-failure

[Install]
WantedBy=multi-user.target
Alias=yii-queue

4.重载systemd配置文件使其生效,相关命令:systemctl daemon-reload;

5.开机自启

 6.启动sudo systemctl restart yii-queue

原文地址:https://www.cnblogs.com/woshixiaozhu/p/13935138.html