LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-17-2020, 06:43 PM   #1
salmanmanekiaa
LQ Newbie
 
Registered: Mar 2020
Posts: 2

Rep: Reputation: Disabled
Systemd with two services and a target unit


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
 
Old 03-18-2020, 01:31 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
As you have not received any replies in the Programming forum, and this appears to be more a configuration problem than an actual programming question, you may receive a better response in the Software, Server or Networking forums.

To request the thread be moved to another forum please use the Report button at bottom of your post.

Good luck!
 
Old 03-18-2020, 02:13 PM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,748

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
I don’t see a question in the OP. Does the setup not work as desired?
If not, what happens? What’s in the log file?
 
Old 03-18-2020, 04:31 PM   #4
salmanmanekiaa
LQ Newbie
 
Registered: Mar 2020
Posts: 2

Original Poster
Rep: Reputation: Disabled
I will try to ellobrate further what I am doing, below I will also post the log and a simple node.js application for test purpose. The problem lies when trying to run the ./bluetooth.sh in ruuvi-bluetooth.service. As seen from the second log the problem is that it cannot connect to the unix socket as its not able to find file/directory. I can confirm that the socket is there and giving `ls` gives -> srwxr-xr-x 1 pi pi 0 Mar 18 23:19 ruuvi.sock

Quote:
pi@raspberrypi:/etc/systemd/system $ sudo systemctl status ruuvi-bluetooth.service
● ruuvi-bluetooth.service - Ruuvi tag bluetooth socket
Loaded: loaded (/etc/systemd/system/ruuvi-bluetooth.service; disabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/ruuvi-bluetooth.service.d
└─override.conf
Active: failed (Result: exit-code) since Wed 2020-03-18 23:19:07 EET; 1min 30s ago
Process: 28160 ExecStart=/usr/bin/sudo /bin/bash /home/pi/cerulean/ruuvi-tag-gateway/bluewalker.sh (code=exited, status=255/EXCEPTION)
The output of
Quote:
journalctl -u ruuvi-bluetooth.service -n 1000 --no-pager
is the following
Quote:
Mar 18 23:19:05 raspberrypi sudo[28089]: root : TTY=unknown ; PWD=/home/pi/cerulean/ruuvi-tag-gateway ; USER=root ; COMMAND=/bin/bash /home/pi/cerulean/ruuvi-tag-gateway/bluewalker.sh
Mar 18 23:19:05 raspberrypi sudo[28089]: pam_unix(sudo:session): session opened for user root by (uid=0)
Mar 18 23:19:05 raspberrypi sudo[28089]: Error: Unable to open unix socket at /tmp/ruuvi.sock (dial unix /tmp/ruuvi.sock: connect: no such file or directory)
Mar 18 23:19:05 raspberrypi sudo[28089]: pam_unix(sudo:session): session closed for user root
Below my node.js application
Code:
var net = require("net");

var unixSocket = net.createServer(function(client) {
	client.on('data', function(data) {
		console.log(data);
	})
})
 
Old 03-20-2020, 05:42 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Moved: This thread is more suitable in Software forum and has been moved per your request to help your thread/question get the exposure it deserves.

Good luck!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
With Linux 4.15.4 or later several systemd services fail, like flush and partition services, for several distros fusion809 Linux - Laptop and Netbook 6 04-13-2018 11:23 PM
How do we get my UNIT(service) name in unit.sevice Boobalan M Linux - Software 6 01-23-2018 05:03 AM
LXer: systemd — unit dependencies and order LXer Syndicated Linux News 0 11-25-2015 01:20 PM
LXer: Hybrid RAID 1 (Mirror) of RAM drive & SATA HDD Using LVM with LUKS [and systemd unit file] on LXer Syndicated Linux News 0 07-29-2014 10:40 AM
Storage unit and IO unit salmanucit Linux - General 2 06-17-2008 11:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration