Hi,
I'm trying to get an initialization script to work with the
service program, and for some strange reason, I cannot get the desired program (in this case Timidity in daemon mode) to start successfully. However, when I execute the script directly, Timidity starts successfully. Here is
/etc/init.d/timidity:
Code:
#!/bin/bash
#
# Startup script for the TiMidity++ ALSA sequencer interface
#
# chkconfig: 2345 20 65
# description: TiMidity is a MIDI to WAVE converter and player that uses Gravis
# Ultrasound(tm) or SoundFont(tm) patch files to generate digital
# audio data from general MIDI files.
#
# processname: timidity
# config: /etc/sysconfig/timidity
### BEGIN INIT INFO
# Provides: timidity
# Should-Start: alsa
# Default-Start: 2 3 4 5
# Short-Description: MIDI to WAVE converter and player
# Description: TiMidity is a MIDI to WAVE converter and player that uses Gravis
# Ultrasound(tm) or SoundFont(tm) patch files to generate digital
# audio data from general MIDI files.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Get config.
. /etc/sysconfig/timidity
[ -x /usr/bin/timidity ] || exit 0
OPTIONS="-iADq -Os"
RETVAL=0
# See how we were called.
case "$1" in
start)
echo "Starting TiMidity++ ALSA sequencer interface:"
if [ ! -f /var/lock/subsys/timidity ]; then
# Parse options
if [[ "$BUFNUM" =~ "[0-9]+" ]] && [[ "$BUFSIZE" =~ "[0-9]+" ]]; then
OPTIONS="${OPTIONS} --buffer-fragments=${BUFNUM},${BUFSIZE}"
fi
[[ "$SAMPLERATE" =~ "[0-9]+" ]] && OPTIONS="$OPTIONS --sampling-freq=$SAMPLERATE"
[ "$ANTIALIAS" = "true" ] && OPTIONS="$OPTIONS --anti-alias"
[[ "$PRIORITY" =~ "[0-9]+" ]] && OPTIONS="$OPTIONS --realtime-priority=$PRIORITY"
[ -n "$EXTRA_OPTIONS" ] && OPTIONS="$OPTIONS $EXTRA_OPTIONS"
daemon timidity $OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/timidity
else
failure
fi
echo
;;
stop)
echo "Shutting down TiMidity++ ALSA sequencer interface:"
if [ -f /var/lock/subsys/timidity ]; then
killproc timidity
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/timidity
else
failure
fi
echo
;;
status)
status timidity
RETVAL=$?
;;
reload)
killproc -HUP timidity
RETVAL=$?
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
*)
echo "Usage: %s {start|stop|status|reload|restart}\n" "$0"
exit 1
esac
exit $RETVAL
and here is
/etc/sysconfig/timidity, if you're curious:
Code:
# Number of buffers, and buffer size in 2^n
BUFNUM=2
BUFSIZE=10
# Sampling rate, default is 44100
SAMPLERATE=22050
# Antialias = "true" enhances sound quality
ANTIALIAS=false
# PRIORITY is the realtime priority. For more detail, see
# manpage sched_setscheduler(2), the part talking about SCHED_FIFO.
# this number is 0-100 inclusive.
#PRIORITY=10
# Any extra timidity options please go here
#EXTRA_OPTIONS=
This is the output I received when I attempted both methods of starting Timidity:
Code:
[root@gateway_nx570xl ~]# /sbin/service timidity start
Starting TiMidity++ ALSA sequencer interface:
*** PULSEAUDIO: Unable to connect: Connection refused
Can't open pcm device 'default'.
Couldn't open ALSA pcm device (`s')
[FAILED]
[root@gateway_nx570xl ~]# /etc/init.d/timidity start
Starting TiMidity++ ALSA sequencer interface:
TiMidity starting in ALSA server mode
Opening sequencer port: 128:0 128:1 128:2 128:3
[ OK ]
This situation seems quite bizarre. Any suggestions on why this happens?