我正在编写一个 python 脚本,该脚本向本地主机 MQTT 代理订阅一些 MQTT 主题,当推送消息时,该脚本将调用同一目录中另一个脚本中的函数,以将更改加载到 SQL 数据库中。
\n在终端中手动运行时,该脚本工作正常:
\npython3 /directory/path/to/file/listen_mqtt.py
但是,我试图让这个文件在 Ubuntu 系统启动时自动执行。我在以下位置创建了一项新服务:
\n/lib/systemd/system/listen_mqtt_py.service
服务描述如下:
\n[Unit]\nDescription=Listen Mqtt\nAfter=mosquitto.service\nWants=network.target\nConflicts=getty@tty1.service\n\n[Service]\nType=simple\nExecStart=/usr/bin/python3 /home/bt/dev/dexter-mqtt-to-sql/listen_mqtt.py\nStandardInput=tty-force\n\n[Install]\nWantedBy=multi-user.target\nRun Code Online (Sandbox Code Playgroud)\n我还启用了该服务并尝试使用以下命令启动该服务:
\nsudo systemctl enable listen_mqtt_py.service
和
\nsudo systemctl start listen_mqtt_py.service
重新启动计算机并尝试手动运行该服务时,我收到以下消息:
\nsudo systemctl status listen_mqtt_py.service\n\xe2\x97\x8f listen_mqtt_py.service - Listen Mqtt\n Loaded: loaded (/lib/systemd/system/listen_mqtt_py.service; enabled; vendor preset: enabled)\n Active: failed (Result: exit-code) since Tue 2020-11-17 13:45:28 AEDT; 14s ago\n Process: 2206 ExecStart=/usr/bin/python3 /home/bt/dev/dexter-mqtt-to-sql/listen_mqtt.py (code=exited, status=1/FAILURE)\n Main PID: 2206 (code=exited, status=1/FAILURE)\n\nNov …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习 docker 的工作原理,在使用 docker-compose 时遇到 yaml 文件的问题。
version: '3.7'
services:
portainer:
container_name: portainer
image: portainer/portainer
volumes:
- portainer_data:/data
- /var/run/docker.sock:/var/run/docker.sock
restart: always
ports:
- "9000:9000"
hass:
container_name: hass
image: homeassistant/home-assistant
volumes:
- /home/flory/home_assistant:/config
- /etc/letsencrypt:/certs
restart: always
network_mode: host
mqtt:
container_name: mqtt
container_name: mqtt
image: eclipse-mosquitto
restart: always
volumes:
- /home/flory/mosquitto/config: /mosquitto/config
- /home/flory/mosquitto/data: /mosquitto/data
- /home/flory/mosquitto/log: /mosquitto/log
ports:
- 1883:1883
- 9000:9000
volumes:
portainer_data:
Run Code Online (Sandbox Code Playgroud)
我收到如下错误:
services.mqtt.volumes 'type' 是必需的属性。
有人可以帮我纠正这个问题吗?