summaryrefslogtreecommitdiffstats
path: root/debian/pulseaudio.init.example
blob: 5f6c29f1de07f1052c3cd64ec1c50acd2b0904e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          pulseaudio
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      avahi-daemon udev network-manager
# Should-Stop:       avahi-daemon 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
#
# Example init file for a system wide pulseaudio daemon.
# If you use system wide mode, you are on your own!
# http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/
#

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_action_msg "PulseAudio not started: 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|force-reload)
		if [ -s $PIDFILE ] && kill -0 $(cat $PIDFILE) >/dev/null 2>&1; then
			pulseaudio_stop
		fi
		pulseaudio_start
		;;
	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|force-reload|status}"
		exit 1
		;;
esac

exit 0