0

I am trying to create a custom script, which has to run automatically during boot. The custom script is running a python script which is using bluetooth. When I run this following line :

systemctl start myCustomService.service 

The script works perfectly !

However when I reboot the computer, I have this following error :

[localhost]# systemctl status myCustomService.service -l

myCustomService.service.service - MycustomScript program

Loaded: loaded (/etc/systemd/system/myCustomService.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Thu 2019-02-21 15:03:38 CET; 1min 39s ago Process: 821 ExecStart=/.../mycustomScript.sh (code=exited, status=1/FAILURE) Main PID: 821 (code=exited, status=1/FAILURE)

Feb 21 15:03:38 localhost mycustomScript.sh[821]: During handling of the above exception, another exception occurred: Feb 21 15:03:38 localhost mycustomScript.sh[821]: Traceback (most recent call last):

Feb 21 15:03:38 localhost mycustomScript.sh[821]: File "main.py", line 69, in

Feb 21 15:03:38 localhost mycustomScript.sh[821]: profiles=[SERIAL_PORT_PROFILE],

Feb 21 15:03:38 localhost mycustomScript.sh[821]: File "/usr/local/lib/python3.6/site-packages/bluetooth/bluez.py", line 266, in advertise_service

Feb 21 15:03:38 localhost mycustomScript.sh[821]: 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

Feb 21 15:03:38 localhost mycustomScript.sh[1]: Unit sample.service entered failed state.

Feb 21 15:03:38 localhost mycustomScript.sh[1]: sample.service failed.

My service is running after bluetooth services, hence, I don't understand why I have this error.

PS : I am using Centos 7

0

Your Python script exits with an error on line 266. Systemd has no idea why it happened but gives you the actual program output in error messages:

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

A dirty workaround in such situations is to add

ExecStartPre=bash -c "sleep 30"

or as many seconds as you think your system needs to start bluetooth devices

  • The problem is coming from the bluetooth device, which is not activated when my script starts, however, I am using Requires and After to wait for the bluetooth activation. But it stills doesn't work – vijayakm Feb 26 at 10:23
  • I solved it ! I added this command on my bash script : " hciconfig hci0 piscan sleep 30" Quite dirty workaround but... I didn't find something else – vijayakm Feb 28 at 15:21
  • Does not really matter where you pause it ) – Igor Voltaic Feb 28 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.