I have Rpi4 with Volumio 2.729 installed. I use Triggerhappy to run a node.js script when keyboard button is pressed - the script will play corresponding internet radio station:
module.paths.push('/lib/node_modules');
var io=require('socket.io-client');
var socket= io.connect('http://127.0.0.1:3000');
socket.on('connect',function(){
socket.emit('replaceAndPlay', {"service":"webradio","uri":"http://185.85.28.148:8000"});
});
Also, when a button is pressed simultaneously with 'M' key, Triggerhappy will run .js script that will bind currently playing station to that button - it works by getting status of volumio and replacing URI in .js script (from example above )that is bound to that button with fs.writeFile().
My problem is, that Triggerhappy can't overwrite .js files. When I run this script manually from terminal it works perfectly.
I managed to run Triggerhappy as root, it didn't help. How can I make Triggerhappy overwrite file, or is there more elegant solution?
EDIT: This is output from sudo systemctl status triggerhappy.service -l
● triggerhappy.service - LSB: triggerhappy hotkey daemon
Loaded: loaded (/etc/init.d/triggerhappy)
Active: active (running) since Thu 2020-04-16 19:58:25 CEST; 4min 44s ago
Process: 640 ExecStart=/etc/init.d/triggerhappy start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/triggerhappy.service
├─ 698 /usr/sbin/thd --daemon --triggers /etc/triggerhappy/triggers.d/ --socket /var/run/thd.socket --pidfile /var/run/thd.pid --user volumio /dev/input/event*
├─2415 /usr/sbin/thd --daemon --triggers /etc/triggerhappy/triggers.d/ --socket /var/run/thd.socket --pidfile /var/run/thd.pid --user volumio /dev/input/event*
├─2416 sh -c node /home/volumio/node-stream/play_uri_1-node.js
├─2417 node /home/volumio/node-stream/play_uri_1-node.js
├─2636 /usr/sbin/thd --daemon --triggers /etc/triggerhappy/triggers.d/ --socket /var/run/thd.socket --pidfile /var/run/thd.pid --user volumio /dev/input/event*
├─2637 sh -c node /home/volumio/node-stream/play_uri_2-node.js
└─2638 node /home/volumio/node-stream/play_uri_2-node.js
No entry about memory.js which is the script that writes in play_uri_x-node.js
ACCEPTED]
By default triggerhappy should run as nobody. One workaround is to grant nobody the right to invoke a specific command by editing your sudo file. But it should not be necessary to use root, your regular user should suffice if it can run the script.
In your triggerhappy configuration, verify that you have a fully qualified-path to your script.
Last but not least, check your log files (syslog, possibly others in /var/log).
triggerhappyasnobody, thennobodyneeds to have access right to the directory. One thing you could do is create a new group, add yourself in it, and then add user nobody too. Change the ownership of the directory to that group. Have a look here for example: Add a User to a Group (or Second Group) on Linux. Or use thesetfaclcommand for ad hoc permissions - see askubuntu.com/a/809562/1050528 - Kate