无法使用 systemctl 在 raspbian jessie 上启动 mosquitto
Can't start mosquitto on raspbian jessie using systemctl
第一次这样做:
systemctl stop mosquitto
update-rc.d mosquitto remove
rm /etc/init.d/mosquitto
单元文件如下:
[Unit]
Description=MQTT v3.1 message broker
After=network.target
Requires=network.target
[Service]
Type=simple
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Restart=always
[Install]
WantedBy=multi-user.target
结果:
sudo systemctl status mosquitto -l
是:
● mosquitto.service - MQTT v3.1 message broker
Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled)
Active: failed (Result: start-limit) since Sun 2017-01-01 19:44:03 GMT; 3min 23s ago
Process: 683 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
Main PID: 683 (code=exited, status=1/FAILURE)
Jan 01 19:44:03 raspberrypi systemd[1]: Unit mosquitto.service entered failed state.
Jan 01 19:44:03 raspberrypi systemd[1]: mosquitto.service holdoff time over, scheduling restart.
Jan 01 19:44:03 raspberrypi systemd[1]: Stopping MQTT v3.1 message broker...
Jan 01 19:44:03 raspberrypi systemd[1]: Starting MQTT v3.1 message broker...
Jan 01 19:44:03 raspberrypi systemd[1]: mosquitto.service start request repeated too quickly, refusing to start.
Jan 01 19:44:03 raspberrypi systemd[1]: Failed to start MQTT v3.1 message broker.
Jan 01 19:44:03 raspberrypi systemd[1]: Unit mosquitto.service entered failed state.
我进行了大量的谷歌搜索,并尝试了一些类似的单元文件,但似乎没有任何效果。
运行 该命令手动 (/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
) 给出:
Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.
Error found at /etc/mosquitto/mosquitto.conf:11.
Error: Unable to open configuration file.
奇怪的是,运行 /usr/sbin/mosquitto
,即没有指定 .conf 文件,工作正常。 /etc/mosquitto/mosquitto.conf 是默认的 .conf 文件,所以即使我没有指定它也应该使用它...
如果出现问题,一个好的开始通常是查看日志文件(假设所有命令都是 运行 root):
journalctl -u mosquitto
现在您的特定错误 (Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.
) 提示您 运行 遇到权限问题。
- 检查
mosquitto
守护程序 运行ning 下的用户。
- 检查此用户是否已 阅读 resp。 写入 访问所有必要的文件(例如日志文件)
注意:如果您 运行 在错误的用户下进行文件创建过程(仅一次就足够 - 例如在测试期间),则很容易获得生成文件的错误权限
第一次这样做:
systemctl stop mosquitto
update-rc.d mosquitto remove
rm /etc/init.d/mosquitto
单元文件如下:
[Unit]
Description=MQTT v3.1 message broker
After=network.target
Requires=network.target
[Service]
Type=simple
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Restart=always
[Install]
WantedBy=multi-user.target
结果:
sudo systemctl status mosquitto -l
是:
● mosquitto.service - MQTT v3.1 message broker
Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled)
Active: failed (Result: start-limit) since Sun 2017-01-01 19:44:03 GMT; 3min 23s ago
Process: 683 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
Main PID: 683 (code=exited, status=1/FAILURE)
Jan 01 19:44:03 raspberrypi systemd[1]: Unit mosquitto.service entered failed state.
Jan 01 19:44:03 raspberrypi systemd[1]: mosquitto.service holdoff time over, scheduling restart.
Jan 01 19:44:03 raspberrypi systemd[1]: Stopping MQTT v3.1 message broker...
Jan 01 19:44:03 raspberrypi systemd[1]: Starting MQTT v3.1 message broker...
Jan 01 19:44:03 raspberrypi systemd[1]: mosquitto.service start request repeated too quickly, refusing to start.
Jan 01 19:44:03 raspberrypi systemd[1]: Failed to start MQTT v3.1 message broker.
Jan 01 19:44:03 raspberrypi systemd[1]: Unit mosquitto.service entered failed state.
我进行了大量的谷歌搜索,并尝试了一些类似的单元文件,但似乎没有任何效果。
运行 该命令手动 (/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
) 给出:
Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.
Error found at /etc/mosquitto/mosquitto.conf:11.
Error: Unable to open configuration file.
奇怪的是,运行 /usr/sbin/mosquitto
,即没有指定 .conf 文件,工作正常。 /etc/mosquitto/mosquitto.conf 是默认的 .conf 文件,所以即使我没有指定它也应该使用它...
如果出现问题,一个好的开始通常是查看日志文件(假设所有命令都是 运行 root):
journalctl -u mosquitto
现在您的特定错误 (Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.
) 提示您 运行 遇到权限问题。
- 检查
mosquitto
守护程序 运行ning 下的用户。 - 检查此用户是否已 阅读 resp。 写入 访问所有必要的文件(例如日志文件)
注意:如果您 运行 在错误的用户下进行文件创建过程(仅一次就足够 - 例如在测试期间),则很容易获得生成文件的错误权限