RabbitMq consumer doesn't run on boot - Raspberry pi 4 - cron

I'm trying to make the rabbitMQ consumer file (consumer.py) run when starting up(boot) Raspberry pi 4. I'm using Corntab. The line that I added to Crontab is below
#reboot sudo python /home/pi/assistant-sdk-python/google-assistant-sdk/assistant/grpc/consumer.py
However, it is not running. I checked through the web interface and found there are no live ques. What am I missing?

Related

Pulseaudio output sink does not exists until user get logged in to X window environment

Setup:
Embedded target device: Rock5B (ARM64)
Linux: Debian 11
Bluetooth stack: Bluez
Audio: Pulseaudio
Window environment: Xfce
I'm writing a Bluetooth application which connects to a headset.
If I manually log into window environment with user credentials and do manual Bluetooth pairing and select manually the output sink it does work as expected.
The same happens if I log into window environment and I run my application remotely using SSH which connects to Bluetooth headset and run the script remotely using SSH and selecting the output sink number 3 (which in that case is Bluetooth headset):
pacmd set-default-sink 3.
On the other hand if the device get started but I do not log into window environment but instead just run same steps remotly using SSH then Blutooth pairing is completed but the Pulseaudio sink number 3 is not present.
I have tried after restart to first run the Pulseaudio manually:
pulseaudio -k
pulseaudio -D
and after that I have run remotely using SSH my app and then select the sink with pacmd. Now pacmd found and selected the sink but when I tried to run the audio file remotely there was no audio output:
PULSE_SERVER=127.0.0.1 cvlc audo.wav
Again if I log into the window environment run everything remotely and run above cvlc the audio is working fine.
Something needs to be setup more than that when windows environment is starting but I can not figure what.

Running a systemd service without sudo privileges

I have a PC that transmits log data over a TCP/IP socket to a Raspberry Pi. I have written a python server program that runs on the Pi, so that when certain keywords are encountered, it has to play the corresponding audio track - this is a gist of the problem I'm currently working on.
Now, I want this server program to run as soon as the Raspberry Pi boots up, and so I wrote a systemd service to enable that. Assuming my server code is named as server.py, my service file looks as follows:
[Unit]
Description=Python Server
[Service]
# Command to execute when the service is started
ExecStart=/usr/bin/python3 -u /usr/bin/server.py
[Install]
WantedBy=multi-user.target
I make this server program executable, and I don't face any issues to start and enable the service (verified by rebooting the Pi as well). Now, taking a step back, I play the audio track on the python server program using the following lines (a little snippet):
import subprocess
subprocess.run(["cvlc", "~/Downloads/doors.wav"])
No errors here, all good. But when the service that runs the server program is started, when the specific keyword is encountered, the audio track does not play - it shows an error:
: [00005565470df480] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
: [0000556547157310] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $D
: [0000556547157310] main interface error: no suitable interface module
: [000055654700c570] main libvlc error: interface "dbus,none" initialization failed
: [0000556547101460] main interface error: no suitable interface module
: [000055654700c570] main libvlc error: interface "globalhotkeys,none" initialization failed
: [0000556547101460] dummy interface: using the dummy interface module...
: [00007f5f98c0b610] idummy demux: command `quit'
This same error shown above occurs when I try to play the audio from the command line with sudo, that is:
cvlc ~/Downloads/doors.wav
which led me to believe that if the service is enabled, then the whole python program corresponding to the service is run with sudo privileges automatically, even if I don't intend that to happen. I did a little bit of digging, but based on what I understand, to run the service, sudo privilege is necessary. I was not able to find a solution to run vlc with sudo, although I understand that ideally sudo privileges should not be given to something such as vlc. Is there a way around this?
This is happening because the PulseAudio server runs under your user, not as root. The service you are starting runs as root and tries to connect to root's PulseAudio server.
You can run specify which user/group to run the service as under the [Service] section with the User and Group directives.
You can also run the service as your user like this:
$ systemctl start --user <service>.service

Reloading code onto raspberry pi 3 and running it

I am currently writing a program that detects if an IoT is compromised (i.e sending information its not supposed to). When this behaviour is detected by the control server, it will then get the device to reset by downloading its uncompromised code functions (which i have on a cloud) and running them. Is there a way to do this. Im using nodejs on my raspberry by the way.
Is there a way to shutdown or reboot a raspberry pi via a script?
You can issue the command:
ssh <user>#<ip address to Pi> 'echo <password> | sudo <full path to shutdown command> -r now'
Replace with the Pi's username, replace with the password, and that path to shutdown (which you can find while connected to the Pi do which shutdown). And fill in the IP address to your PI.
That should reboot your Pi.

Run a script after Bluetooth is configured and running - Rasperry Pi 3

I'm trying to automatically call a program at boot that uses Bluetooth. However, the program is being called before Bluetooth is configured and running.
I've tried calling the program in two ways:
Using a script in init.d and registered with update-rc.d with this line in the init: # Required-Start: $all
Calling it from /etc/rc.local
Neither of these work as desired. They both start the program, but before Bluetooth is configured and running.
What is the best way to force a script or program to run after Bluetooth?
Below are some select lines from the boot sequence so you can see the issue I'm having:
[ OK ] Started Login Service.
[ OK ] Started Getty on tty1.
**Where my program is currently executing**
[ OK ] Started Configure Bluetooth Modems connected by UART.
[ OK ] Reached Target Bluetooth
**Where I want my program to be executing**
Raspbian GNU/Linux 8 tty1
login:
The new init system for Debian 8 "Jessie" is systemd. The old way in Debian 7 "Wheezy" was Sysv with runlevels and /etc/inittab. A drawback of using crontab to run your program will be, if the script execution crashes, it dies forever. Restarting a script automatically if its ends is called "respawn".
As you can see, the Bluetooth Service is running and prints that a "Target" is reached. To create your own service, which runs after bluetooth startup, and respawns with systemd just create a file in /etc/systemd/system/ i.e. my_program.service
[Unit]
Desription=my_program with systemd, respawn, after bluetooth
After=bluetooth.target
[Service]
ExecStart=node /home/pi/workspace/my_program
Restart=always
[Install]
WantedBy=multi-user.target
and activate it
systemctl enable my_program.service
reboot or start it manually
systemctl daemon-reload
systemctl start my_program.service
If one kills the process or reboots, my_program will be restarted automatically some seconds later.
For anyone running Raspbian 9 (stretch)
I tried out #andpei's answer and my application still wasn't waiting for bluetooth to start up. I was able to solve this by adding "Requires".
[Unit]
Desription=my_program with systemd, respawn, after bluetooth
After=bluetooth.target
Requires=bluetooth.target
Using crontab, I was able to make it work with the following line:
#reboot sleep 5 && node /home/pi/workspace/my_program
Not ideal but it works for now. I'm open to any better answers.

Error setting sh script at startup - Intel Galileo Gen 1

I have running a node webserver on Intel Galileo Gen 1 and a normal arduino sketch which saves data from UDP messages.
I've tried to use the call system to set the timezone, date and start the webserver, but doesn't work very well. Then I created a sh script with the same commands, and created the corresponding links to the file in "/etc/init.d" using "update-rc.d startServer.sh defaults".
export TZ=CET-1CEST,M3.5.0,M10.5.0/3
rdate 132.163.4.101 && hwclock --systohc
node /media/mmcb1k0p1/Server/server2.js
It works, but Galileo does not start ssh, since I cannot connect anymore if it's running + sometimes the arduino sketch is not running. It seems like Galileo is currently executing the webserver and waits for it to finish to execute the rest, like an active process, instead of working in background.
Any help?
Run the node server as a background process:
node /media/mmcb1k0p1/Server/server2.js &
Note the & at the end.

Resources