我想在 Ubuntu VPS 的两个不同端口上运行两种不同的服务。为此,我创建了两个不同的服务文件
/etc/systemd/system/myfirst-server.service
和
/etc/systemd/system/mysecond-server.service
这些文件是
[Unit]
Description=Chat Server
[Service]
ExecStart=/usr/bin/php /var/www/vhosts/domain.com/path1/bin/myfirst-server.php
StandardOutput=null
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
和
[Unit]
Description=Chat Server
[Service]
ExecStart=/usr/bin/php /var/www/vhosts/domain.com/path2/bin/mysecond-server.php
StandardOutput=null
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
现在我正在运行它们
sudo systemctl enable myfirst-server.service
sudo systemctl enable mysecond-server.service
sudo systemctl daemon-reload
sudo systemctl start myfirst-server.service
sudo systemctl start mysecond-server.service
现在的问题是,如果我运行其中一个,它运行得很好,但是其中两个开始表现出不可预测的行为——有时它们运行良好,而另一种则不运行。奇怪的是,它们都对 WSS 连接的响应非常好。
有关如何运行两项服务的任何帮助
ExecStart=/usr/bin/php /var/www/vhosts/domain.com/path1/bin/myfirst-server.php
ExecStart=/usr/bin/php /var/www/vhosts/domain.com/path2/bin/mysecond-server.php
同时受到高度赞赏
最佳答案
经过几天的测试,结果证明这是我们应该如何完成任务的。问题出在其他地方。实际上,我的两台服务器都在使用 MySQL 连接,结果证明 MySQL 在 8 小时不活动后超时并断开连接。所以现在我已经通过将 cron 作业添加为 root 来修复它,这些作业使用 systemctl 在 8 小时后重新启动服务。它对我有用。随着服务器负载的增加,解决方案也会不断发展。
谢谢
关于php - Ubuntu 运行多个 .service 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60398677/