googlecreativelab / coder

A simple way to make web stuff on Raspberry Pi
http://goo.gl/coder
Apache License 2.0
2.43k stars 274 forks source link

TTS and Coder as root #90

Open miniBloq opened 10 years ago

miniBloq commented 10 years ago

Hi,

I was experimenting with Text2Speech, and found that most TTS node packages do not work with Coder (in fact none in my experiments). Finally, I wrote code to run espeak commands using child_process, and it only worked when running Coder as root. Here is the JavaScript code added at the end of the NODE code (NODE tab in Coder) which worked only when running Coder as root:

var run = require('child_process').exec;

exports.on_socket_say = function( socket, data ) { if ( data.value !== "undefined" ) { console.log('running server side code'); run('espeak -ven-us+f4 -p50 -s170 "Hello humans" --stdout | aplay', function callback(error, stdout, stderr){ console.log('error: ' + error); console.log('stderr: ' + stderr); console.log('stdout: ' + stdout); });
} };

I think that this behavior could also happen for other packages. So I did these changes (just replaced coder user by root) to the coder-daemon and it's working now:


do_start() {

Return

0 if daemon has been started

1 if daemon was already running

2 if daemon could not be started

start-stop-daemon --start --background --quiet --pidfile $PIDFILE --exec $DAEMON \ --chuid root --user root --umask $UMASK --chdir $DAEMON_PATH --test > /dev/null RETVAL="$?" [ "$RETVAL" = "0" ] || return 1

start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile --exec $DA$ --chuid root --user root --umask $UMASK --chdir $DAEMON_PATH -- $DAEMON_ARGS RETVAL="$?" [ "$RETVAL" = "0" ] || return 2 }


Also changed this:

start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user root --pidfile $PIDFILE


But I have a question: Is there any side effect or something which may stop to work or malfunction by not running the Coder daemon with the Coder user? Or is this okay?

Of course, I can give further details of what happened in the console when running that code as Coder instead of root, but basically, it had problems with the ALSA drivers.

Thanks! Julián

jmstriegel commented 9 years ago

Hmmm. It would be fun to get this working right inside coder, and without using the root user. Do you know what permissions it needs? Can the pi user run this from the command line without using sudo?

plietar commented 9 years ago

Adding the pi user to the audio group should be enough