使用 systemtcl 时蓝牙出现错误

使用 systemtcl 时蓝牙出现错误

我正在尝试创建一个自定义脚本,该脚本必须在启动期间自动运行。自定义脚本正在运行使用蓝牙的 Python 脚本。当我运行以下行时:

systemctl start myCustomService.service 

脚本运行完美!

但是,当我重新启动计算机时,出现以下错误:

[本地主机]# systemctl status myCustomService.service -l

myCustomService.service.service - MycustomScript 程序

已加载:已加载(/etc/systemd/system/myCustomService.service;已启用;供应商预设:已禁用)活动:失败(结果:退出代码)自 2019-02-21 星期四 15:03:38 CET;1 分 39 秒前进程:821 ExecStart=/.../mycustomScript.sh(代码=退出,状态=1/失败)主 PID:821(代码=退出,状态=1/失败)

2 月 21 日 15:03:38 localhost mycustomScript.sh[821]: 在处理上述异常期间,发生了另一个异常:2 月 21 日 15:03:38 localhost mycustomScript.sh[821]: 回溯(最近一次调用最后一次):

2 月 21 日 15:03:38 localhost mycustomScript.sh[821]: 文件“main.py”,第 69 行,位于

2 月 21 日 15:03:38 localhost mycustomScript.sh[821]: 配置文件 = [SERIAL_PORT_PROFILE],

2 月 21 日 15:03:38 localhost mycustomScript.sh[821]: 文件“/usr/local/lib/python3.6/site-packages/bluetooth/bluez.py”,第 266 行,位于 advertise_service

2 月 21 日 15:03:38 localhost mycustomScript.sh[821]: 引发 BluetoothError (*e.args)

2 月 21 日 15:03:38 localhost mycustomScript.sh[821]: bluetooth.btcommon.BluetoothError: 错误,没有可广告的设备。

2 月 21 日 15:03:38 localhost mycustomScript.sh[1]: sample.service: 主进程已退出,代码=已退出,状态=1/失败

2 月 21 日 15:03:38 localhost mycustomScript.sh[1]: 单元 sample.service 进入失败状态。

2 月 21 日 15:03:38 localhost mycustomScript.sh[1]: sample.service 失败。

我的服务是在蓝牙服务之后运行的,因此,我不明白为什么会出现这个错误。

PS:我使用的是 Centos 7

答案1

您的 Python 脚本在第 266 行因错误而退出。Systemd 不知道为什么会发生这种情况,但会在错误消息中向您提供实际的程序输出:

File "/usr/local/lib/python3.6/site-packages/bluetooth/bluez.py", line 266, in advertise_service
raise BluetoothError (*e.args)

Feb 21 15:03:38 localhost mycustomScript.sh[821]: bluetooth.btcommon.BluetoothError: error no advertisable device.

Feb 21 15:03:38 localhost mycustomScript.sh[1]: sample.service: main process exited, code=exited, status=1/FAILURE

在这种情况下,一个肮脏的解决方法是添加

ExecStartPre=bash -c "sleep 30"

或者您认为系统启动蓝牙设备所需的秒数

相关内容