LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-28-2014, 07:48 PM   #1
VideoTrack
LQ Newbie
 
Registered: Mar 2014
Posts: 17

Rep: Reputation: Disabled
Pulse Audio not working if terminal logged out


I hope some experts can assist with solving my problem

My application runs on a stand-alone embedded system and doesn't require to be logged on to operate. My application starts at boot time and is a standalone app running on an isolated embedded system. It monitors data on a COM port and needs to play a wav file under certain circumstances, triggered by data from the COM port.

I am running Crunchbang O/S

1 - When the system boots my application starts under root, but there is no audio

2 - If I login to a terminal session there is still no audio

3 - If I restart the application under my logged-in account there is audio

4 - If I log out, there is no audio again

5 - If I log in to the terminal again, audio works again

My app runs as UID of root

This is the error message produced when my app calls aplay when I am logged out:
"sending: /usr/bin/aplay"
Code:
Invalid MIT-MAGIC-COOKIE-1 keyxcb_connection_has_error() returned true
Invalid MIT-MAGIC-COOKIE-1 keyxcb_connection_has_error() returned true
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

aplay: main:682: audio open error: Connection refused
This is the message when my app calls aplay and I am logged in
"sending: /usr/bin/aplay"
Code:
Playing WAVE '/usr/mms/cfg/audio_files/12-1-10-1' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
When I am logged on, ps -Af shows these possibly related processes
Code:
1000      4441     1  0 11:04 ?        00:00:00 pnmixer
1000      4460     1  0 11:04 ?        00:00:00 xfce4-volumed
1000      4461     1  0 11:04 ?        00:00:00 xfce4-power-manager
1000      4488     1  0 11:04 ?        00:00:00 /usr/bin/pulseaudio --start
1000      4584     1  0 11:05 ?        00:00:00 /usr/lib/gvfs/gvfs-gdu-volume-monitor
1000      4586     1  0 11:05 ?        00:00:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
1000      4588     1  0 11:05 ?        00:00:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
None of these processes are there when I am logged out

I think I need pulse audio (and maybe other sound related programs) to start as root when the system is booted, rather than when a user logs in. I read articles advising against this, but my app is a standalone app running on an isolated embedded system, so I have weighed up the risks.

Does this sound feasible, and can anybody advise how I get pulseaudio (and other required audio processes) to start at boot-time on Crunchbang?

I am very new to Linux.

Thank you all

VideoTrack
 
Old 03-28-2014, 08:07 PM   #2
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 823

Rep: Reputation: 237Reputation: 237Reputation: 237
As an easy fix you could install screen. That's a small command line application that allows you to "disconnect" from a terminal session without actually logging out. All process you started in the screen session will just continue running as if you were still logged in.

So you could

Code:
apt-get install screen
Then type
Code:
screen
Start the processes you need and type Ctrl-A, and then D to disconnect from the session.
Then logout and enjoy.
Oh, and if you want to reattach type
Code:
screen -r
 
Old 03-28-2014, 08:15 PM   #3
VideoTrack
LQ Newbie
 
Registered: Mar 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Thanks Joe for the idea, appreciated.

My application runs remotely, if there is a power outage, it needs to automatically start and work when the power is restored. That's why the app is started automatically from /etc/rcx.d/ folders.
Because the app is remote in the field, it's not possible to travel to it if there was a power outage, or even to know if there had been a power outage in the first place.

Regards
VideoTrack
 
Old 03-28-2014, 08:41 PM   #4
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 823

Rep: Reputation: 237Reputation: 237Reputation: 237
Hmm, to tell the truth I am not very experienced with pulse audio, but after a bit of searching I came across this guide here:

http://rudd-o.com/linux-and-free-sof...all-your-users

To me this looks like it is what you are looking for...

Last edited by joe_2000; 03-28-2014 at 08:41 PM. Reason: Corrected Code tags to url tags
 
1 members found this post helpful.
Old 03-28-2014, 09:29 PM   #5
VideoTrack
LQ Newbie
 
Registered: Mar 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Joe Thank you for your support, it is really appreciated

My system doesn't have the file: /etc/event.d/pulseaudio

I did find a file: /etc/init.d/pulseaudio

The file seems to be the correct one, but I haven't a clue where to insert the additional text.

Is anybody able to review the content below and suggest where the insertion should occur?

Many thanks
VideoTrack

Code:
#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          pulseaudio esound
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      udev network-manager
# Should-Stop:       udev network-manager
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start the PulseAudio sound server
# Description:       System mode startup script for
#                    the PulseAudio sound server.
### END INIT INFO

DAEMON=/usr/bin/pulseaudio
PIDDIR=/var/run/pulse
PIDFILE=$PIDDIR/pid
DAEMONUSER=pulse
PATH=/sbin:/bin:/usr/sbin:/usr/bin

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

PULSEAUDIO_SYSTEM_START=0
DISALLOW_MODULE_LOADING=1
test -f /etc/default/pulseaudio && . /etc/default/pulseaudio
if [ "$PULSEAUDIO_SYSTEM_START" != "1" ]; then
	log_warning_msg "PulseAudio configured for per-user sessions"
	exit 0
fi

pulseaudio_start () {
	log_daemon_msg "Starting system PulseAudio Daemon"
	if [ ! -d $PIDDIR ]; then
		mkdir -p $PIDDIR
		chown $DAEMONUSER:$DAEMONUSER $PIDDIR
	fi
	start-stop-daemon -x $DAEMON -p $PIDFILE --start -- --system --disallow-exit --disallow-module-loading=$DISALLOW_MODULE_LOADING --daemonize --log-target=syslog --high-priority
	status=$?
	if [ -e /var/run/pulse/.esd_auth ]; then
		chown pulse:pulse-access /var/run/pulse/.esd_auth
		chmod 640 /var/run/pulse/.esd_auth
	fi
	if [ -e /var/run/pulse/.pulse-cookie ]; then
		chown pulse:pulse-access /var/run/pulse/.pulse-cookie
		chmod 640 /var/run/pulse/.pulse-cookie
	fi
	log_end_msg ${status}
}

pulseaudio_stop () {
	log_daemon_msg "Stopping system PulseAudio Daemon"
	start-stop-daemon -p $PIDFILE --stop --retry 5 || echo -n "...which is not running"
	log_end_msg $?
}

case "$1" in
	start|stop)
		pulseaudio_${1}
		;;
	restart|reload|force-reload)
		if [ -s $PIDFILE ] && kill -0 $(cat $PIDFILE) >/dev/null 2>&1; then
			pulseaudio_stop
			pulseaudio_start
		fi
		;;
	force-stop)
		pulseaudio_stop
		killall pulseaudio || true
		sleep 2
		killall -9 pulseaudio || true
		;;
	status)
		status_of_proc -p $PIDFILE "$DAEMON" "system-wide PulseAudio" && exit 0 || exit $?
		;;
	*)
		echo "Usage: /etc/init.d/pulseaudio {start|stop|force-stop|restart|reload|force-reload|status}"
		exit 1
		;;
esac

exit 0
This is the code segment that is recommended to be inserted in the above file:
Code:
start on runlevel [2345]
stop on runlevel [016]

exec pulseaudio --system --realtime --log-target=syslog

respawn

description "PulseAudio system server"

pre-start script
	for a in `seq 60` ; do
		sleep 1
		killall -0 hald && killall -0 dbus-daemon && break
	done
end script

post-start script
	( sleep 1 ; paplay /usr/share/sounds/login.wav ) &
end script
 
Old 03-29-2014, 07:01 AM   #6
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 823

Rep: Reputation: 237Reputation: 237Reputation: 237
Hmm, I think you have identified the right files. I do not know enough about the Fedora init system to give you a reliable answer.
But e.g. this part
Code:
start on runlevel [2345]
stop on runlevel [016]
is something you would not put into the actual init script under debian (the base for crunchbang). I could probably take an educated guess on how to fiddle this together, but it would be trial and error, and others in this forum could probably give you more reliable advice.
But what becomes clear from the site is that pulse audio by default requires a user to be logged in, which is in line with your findings.
Unless someone else here steps in I can see two possible options for you
1) use your favorite search engine to find a similar guide that works for the debian init system
2) read up on how to write init scripts under debian and translate yourself.

You may find the following resources useful for the second option
https://www.debian-administration.org/articles/28
https://wiki.debian.org/LSBInitScripts
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is Pulse AUdio Sunfist Linux - Newbie 23 08-12-2013 05:58 PM
[SOLVED] Problem with Pulse Audio codeman1234 Linux - Software 15 01-13-2012 11:00 AM
[SOLVED] Pulse Audio Problem vivanguarda Slackware 9 01-23-2011 12:02 PM
pulse audio sulekha Ubuntu 1 02-10-2009 05:48 PM
how can i get pulse audio to work i xfce deathalele Linux - Software 0 08-30-2008 07:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration