share
Unix & LinuxHow to use Triggerhappy deamon to overwrite files
[0] [1] Loproc
[2020-04-16 13:34:13]
[ raspberry-pi daemon node.js triggerhappy ]
[ https://unix.stackexchange.com/questions/580459/how-to-use-triggerhappy-deamon-to-overwrite-files ]

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

[0] [2020-04-16 15:55:29] Kate [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).


I tried now to run triggerhappy as nobody and also as user volumio. Triggerhappy executes station changing scripts successfully, but writing in file does not. What do you mean by fully qualified path? What should I edit in sudo file? - Loproc
Sounds like a permission issue then. If you are running triggerhappy as nobody, then nobody needs 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 the setfacl command for ad hoc permissions - see askubuntu.com/a/809562/1050528 - Kate
Thank you. It indeed was a permissions problem. I had all necessary permisions on files themselves, but not on my home folder. What also worked was to move the script to root directory / - Loproc
1