root@ubuntu:~# vim /etc/systemd/system/swoole-demo.service
[Unit]
Description=这里填写Service描述
After=network.target remote-fs.target syslog.target
[Service]
Type=simple
LimitNOFILE=65535
ExecStart=/program/php/bin/php /inetpub/wwwroot/www_domain_com/cmd/server.php
ExecReload=/bin/kill -USR1 $MAINPID
StandardOutput=append:/inetpub/wwwroot/www_domain_com/data/service.standard.output
StandardError=append:/inetpub/wwwroot/www_domain_com/data/service.standard.error
[Install]
WantedBy=multi-user.target
root@ubuntu:~# systemctl daemon-reload
说明①:每次修改了.service文件都要执行“systemctl daemon-reload”才能重新加载.service文件最新配置。
说明②:程序里的echo、print_r等输出内容都会被写入StandardOutput参数指定的文件。
说明③:Swoole程序不要设置“daemonize => true”,原因可看官方文档:https://wiki.swoole.com/zh-cn/#/server/setting?id=daemonize。
管理命令
root@ubuntu:~# systemctl status swoole-demo
root@ubuntu:~# systemctl start swoole-demo
root@ubuntu:~# systemctl stop swoole-demo
root@ubuntu:~# systemctl restart swoole-demo 注:没有reload操作,执行reload操作会启动失败
root@ubuntu:~# systemctl enable swoole-demo
root@ubuntu:~# systemctl disable swoole-demo