1

I am following this tutorial on using a mobile phone's accelerometer.

In order for it to work properly you have to run three commands on startup every time...

rfkill unblock bluetooth
killall bluetoothd
hciconfig hci0 up

Is there a way to do this with a script on startup instead of manually doing it every time?

  • Have tou tried the cookbook instructions? (I don'tknow if they're up-to-date but they look plausible.) – Gilles Aug 26 '16 at 22:02
1

Most systems will automatically load /etc/rc.local on startup when present, so you just have to put your commands in there and that should do the trick.

You should make sure it is executable by root, but it probably already is.

  • I am really keen to try this out, I am currently putting all my system startup commands in my ~/.zshrc file. as all the other places which are often recommended don't always work. do you know if /etc/rc.local is run late in boot, i.e. after all the graphical system is ready? for example, could I put xset commands targeting X server in there? – the_velour_fog Aug 26 '16 at 1:30
  • @the_velour_fog: The .zshrc file will run once per session, not per boot. This is not suitable for every command you need to run on startup. I honestly don't know for your question on xset though, but it should take you 5-10 minutes to find out. – Julie Pelletier Aug 26 '16 at 1:33
  • thanks, yes running the system startup commands every time I launch a new shell is overkill, but until now no other solution has worked. The other problem, is the system startup commands don't get run at all until I have launched a shell. Unfortunately I can't simply reboot to test, I've got too many daemons that won't restart, text editor sessions that might get lost and USB device plugged in which will lose state if I reboot – the_velour_fog Aug 26 '16 at 1:47
  • @the_velour_fog: In my experience, when you're in such a situation is when you should put in efforts to properly automate your startup or otherwise it can quickly become a nightmare. – Julie Pelletier Aug 26 '16 at 1:49
  • yes, well I will try your /etc/rc.local solution on next reboot, and hopefully that will get me one step closer to having a sane system! – the_velour_fog Aug 26 '16 at 1:56
0

If your system uses systemd, you could write a oneshot service that executes the command once, at system boot.

First, create a file /opt/scripts/configure-bluetooth.sh and put your commands in:

#!/bin/bash
rfkill unblock bluetooth
killall bluetoothd
hciconfig hci0 up

And make the file executable: chmod +x /opt/scripts/configure-bluetooth.sh

The create a new service unit: /etc/systemd/system/configure-bluetooth.service That contains:

[Unit]
Description=Configure bluetooth

[Service]
Type=oneshot
ExecStart=/opt/scripts/configure-bluetooth.sh

[Install]
WantedBy=multi-user.target

You should now run systemctl daemon-reload so that systemd detects the new service. To test it, run systemctl start configure-bluetooth.service.

Once you are sure that it works, you can enable it on boot with: systemctl enable configure-bluetooth.service

  • It works but every time I reboot the Edison I have to run the start command. I have tried multiple times to set this up but seems as though I doesn't automatically start. – Matthew Jackaon Aug 31 '16 at 14:55
  • I was probably wrong on the WantedBy target, see this link. Could you try to change WantedBy=multi-user.target to WantedBy=default.target? You might also need to use systemctl --user enable configure.bluetooth as described there. – Bram Sep 1 '16 at 17:18
  • I tried and after systemctl --user... I got "Failed to get D-Bus connection: Connection refused" – Matthew Jackaon Sep 2 '16 at 0:10

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.