Article 50VYG Systemd with two services and a target unit

Systemd with two services and a target unit

by
salmanmanekiaa
from LinuxQuestions.org on (#50VYG)
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.targetr-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.targetr-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.targetand 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 $SOCKETPATHlatest?d=yIl2AUoC8zA latest?i=zzu-aHdWtjE:b46kjAWlPyY:F7zBnMy latest?i=zzu-aHdWtjE:b46kjAWlPyY:V_sGLiP latest?d=qj6IDK7rITs latest?i=zzu-aHdWtjE:b46kjAWlPyY:gIN9vFwzzu-aHdWtjE
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments