I've written a simple init.d script to start an hardware monitor script. It works fine except it cannot access the alsa audio service:

#! /bin/sh


case $1 in
        say "starting service hwleds..."
        python $SCRIPT_PATH &
        exit $?
        pkill -f "python $SCRIPT_PATH"
        exit $?
        $0 stop
        sleep 1
        $0 start
        echo "Usage: $0 {start|stop|restart}"
        exit 1

exit 1

The error i get from both the say command and the python script is:

audio_open_alsa: failed to open audio device default. Operation not permitted

edit: The python script can access alsa if it is started normally by the root user via an interactive shell, it only fails if it is started as a service during boot or via service hwleds start.

My actual /root/.asoundrc:

defaults.pcm.card 0
defaults.pcm.device 3

ctl.equal {
  type equal;

pcm.plugequal {
  type equal;
  # Modify the line below if you don't
  # want to use sound card 0.
  slave.pcm "plughw:0,3";
  # or if you want to use with multiple applications output to dmix
  # slave.pcm "plug:dmix"

#pcm.equal {
  # Or if you want the equalizer to be your
  # default soundcard uncomment the following
  # line and comment the above line.
 pcm.!default {
  type plug;
  slave.pcm plugequal;
  • 2
    As which user executes this script? Root? Which is the default device (aplay -L and check /etc/asound.conf and ~/.asoundrc for this user, e.g. root)? Maybe a default device doesn't exist for root on your system? – dirkt Mar 17 '17 at 8:06
  • Check the permissions on the device nodes in /dev/snd/. – CL. Mar 17 '17 at 8:38
  • @dirkt: the script is executed as root (checked with whoami). Also i'm quite sure root can access the default alsa device because this is puppy linux. – eadmaster Mar 17 '17 at 11:14
  • The point is not accessing the default device. ALSA has user-specific sound configuration, so even if normal users do have a default device defined (which is just an alias for some other device), that doesn't mean root does. So log in as root, and try aplay -D default some_wav_file. Then do aplay -L etc. – dirkt Mar 17 '17 at 13:17
  • Also, I'd be kind of reluctant to run a python script as root, given you could run it as a less privileged user instead who is member in a group that has access to leds and sound device nodes. – dirkt Mar 17 '17 at 13:19

Had the same problem on volumio. Solved by removing .alsaequal.bin from /var/lib/mpd/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.