Hi,
I am new to the forum and systemd. Using both for the first time
I have a scenario, in which I have a node js application running and data coming from bluetooth. The nodejs app has a socket open to the bluetooth data. The sequence in which I want to do this is
1. Run the node.js app
2. Run the script that listens to the bluetooth and pass on to the socket.
3. If the node app crashes/restarts/exits then delete the socket
Following is what I have done so far. I have create two service and a unit target but it fails when it tries to execute the bluewalker.sh in the bluetooth.service.
app-gateway.target
Code:
[Unit]
Description=Gateway application
Requires=r-bluetooth.service r-gateway.service
After=r-bluetooth.service r-gateway.service
[Install]
WantedBy=multi-user.target
r-bluetooth.service
Code:
[Unit]
Description=bluetooth socket
PartOf=app-gateway.target
[Service]
ExecStartPre=-rm -f /tmp/data.sock
ExecStart=/usr/bin/sudo /bin/bash /home/pi/gateway/bluewalker.sh
Restart=always
Environment=PATH=/usr/bin:/usr/local/bin
[Install]
WantedBy=app-gateway.target
r-gateway.service
Code:
[Unit]
Description=Tag gateway
PartOf=app-gateway.target
[Service]
Type=forking
ExecStart=node /home/pi/gateway/index.js
User=pi
Environment=PATH=/usr/bin:/usr/local/bin
[Install]
WantedBy=app-gateway.target
and the
bluewalker.sh
Code:
#!/bin/bash
SOCKETPATH="/tmp/data.sock"
hciconfig hci0 down
/home/pi/go/bin/bluewalker -device hci0 -ruuvi -active -json -duration -1 -unix $SOCKETPATH