Lufa
October 24th, 2013, 07:36 AM
Hi! Recently I had to install darkice on Ubuntu 12.04 (and 13.10) and faced a problem many other users has: Darkice won't start on boot, Darkice won't start using "service darkice start/stop" method.
There was a few (http://ubuntuforums.org/showthread.php?t=1780884) suggestions (http://ubuntuforums.org/showthread.php?t=1642334) using cron and custom scripts.
I figured out how to do it natively, in Ubuntu-way and want to share my experience with community.
-------------------------------
So. There are few problems with Darkice startup script (/init.d/darkice) provided by package system.
1) It does not create Darkice PID-file on start.
2) It Does not delete Darkice PID-file on stop. ;)
3) It fail to check whether process is running or not.
4) Darkice can not start on boot properly (even if startup script was properly modified).
-------------------------------
Simple To-Do list:
(changed files published at the end of this post)
1
In /etc/init.d/darkice find:
start-stop-daemon --start --quiet --pidfile $PIDFILE \
and replace it with:
start-stop-daemon --start --quiet -m --pidfile $PIDFILE \
2
In /etc/init.d/darkice find:
stop_server() {
# Stop the process using the wrapper
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec $DAEMON
errcode=$?
add after (with the new line):
rm $PIDFILE
3
In /etc/init.d/darkice find:
running() {
# Check if the process is running looking at /proc
# (works for all users)
add after (with the new line):
sleep 1
4
In /etc/default/darkice check that you have
RUN=yes
5
Add default user nobody to the audio group (in my case, to work with ALSA):
adduser nobody audio
or change user to whoever you need in /etc/default/darkice.
6
Fix upstart problem (it seems Darkice is trying to start on boot too early):
update-rc.d -f darkice remove
update-rc.d darkice defaults 99
That's it! I have Darkice, controlled by upstart scripts (service darkice start/stop) running on boot.
Appendix
/etc/init.d/darkice diff:
86c86
<
---
> sleep 1
96c96
< start-stop-daemon --start --quiet --pidfile $PIDFILE \
---
> start-stop-daemon --start --quiet -m --pidfile $PIDFILE \
106a107
> rm $PIDFILE
184d184
<
/etc/init.d/darkice full code:
#!/bin/sh
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
# Copyright (c) 2009 Jochen Friedrich <jochen@scram.de>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License with
# the Debian operating system, in /usr/share/common-licenses/GPL; if
# not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
#
### BEGIN INIT INFO
# Provides: darkice
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Live audio streamer
# Description: DarkIce is an IceCast, IceCast2 and ShoutCast
# live audio streamer.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=darkice
DAEMON=/usr/bin/$NAME
DESC="Live audio streamer"
LOGDIR=/var/log
USER=nobody
GROUP=nogroup
PIDFILE=/var/run/$NAME.pid
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
# Default options, these can be overriden by the information
# at /etc/default/$NAME
DAEMON_OPTS="" # Additional options given to the server
DIETIME=2 # Time to wait for the server to die, in seconds
# If this value is set too low you might not
# let some servers to die gracefully and
# 'restart' will not work
# Include defaults if available
if [ -f /etc/default/$NAME ] ; then
. /etc/default/$NAME
fi
# Use this if you want the user to explicitly set 'RUN' in
# /etc/default/
if [ "x$RUN" != "xyes" ] ; then
exit 0
fi
set -e
running_pid() {
# Check if a given process pid's cmdline matches a given name
pid=$1
name=$2
[ -z "$pid" ] && return 1
[ ! -d /proc/$pid ] && return 1
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
# Is this the expected server
[ "$cmd" != "$name" ] && return 1
return 0
}
running() {
# Check if the process is running looking at /proc
# (works for all users)
sleep 1
# No pidfile, probably no daemon present
[ ! -f "$PIDFILE" ] && return 1
pid=`cat $PIDFILE`
running_pid $pid $DAEMON || return 1
return 0
}
start_server() {
# Start the process using the wrapper
start-stop-daemon --start --quiet -m --pidfile $PIDFILE \
--background --chuid $USER:$GROUP --exec $DAEMON -- $DAEMON_OPTS
errcode=$?
return $errcode
}
stop_server() {
# Stop the process using the wrapper
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec $DAEMON
errcode=$?
rm $PIDFILE
return $errcode
}
force_stop() {
# Force the process to die killing it manually
[ ! -e "$PIDFILE" ] && return
if running ; then
kill -15 $pid
# Is it really dead?
sleep "$DIETIME"s
if running ; then
kill -9 $pid
sleep "$DIETIME"s
if running ; then
echo "Cannot kill $NAME (pid=$pid)!"
exit 1
fi
fi
fi
rm -f $PIDFILE
}
case "$1" in
start)
log_daemon_msg "Starting $DESC " "$NAME"
# Check if it's running first
if running ; then
log_progress_msg "apparently already running"
log_end_msg 0
exit 0
fi
if start_server && running ; then
# It's ok, the server started and is running
log_end_msg 0
else
# Either we could not start it or it is not running
# after we did
# NOTE: Some servers might die some time after they start,
# this code does not try to detect this and might give
# a false positive (use 'status' for that)
log_end_msg 1
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
if running ; then
# Only stop the server if we see it running
stop_server
log_end_msg $?
else
# If it's not running don't do anything
log_progress_msg "apparently not running"
log_end_msg 0
exit 0
fi
;;
force-stop)
# First try to stop gracefully the program
$0 stop
if running; then
# If it's still running try to kill it more forcefully
log_daemon_msg "Stopping (force) $DESC" "$NAME"
force_stop
log_end_msg $?
fi
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
stop_server
# Wait some sensible amount, some server need this
[ -n "$DIETIME" ] && sleep $DIETIME
start_server
running
log_end_msg $?
;;
status)
log_daemon_msg "Checking status of $DESC" "$NAME"
if running ; then
log_progress_msg "running"
log_end_msg 0
else
log_progress_msg "apparently not running"
log_end_msg 1
exit 1
fi
;;
reload)
log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
log_warning_msg "cannot re-read the config file (use restart)."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
Hope this will help someone. Cheers! ;)
P.S. I am wondering how to propose this changes to the package maintainer. Tnx.
There was a few (http://ubuntuforums.org/showthread.php?t=1780884) suggestions (http://ubuntuforums.org/showthread.php?t=1642334) using cron and custom scripts.
I figured out how to do it natively, in Ubuntu-way and want to share my experience with community.
-------------------------------
So. There are few problems with Darkice startup script (/init.d/darkice) provided by package system.
1) It does not create Darkice PID-file on start.
2) It Does not delete Darkice PID-file on stop. ;)
3) It fail to check whether process is running or not.
4) Darkice can not start on boot properly (even if startup script was properly modified).
-------------------------------
Simple To-Do list:
(changed files published at the end of this post)
1
In /etc/init.d/darkice find:
start-stop-daemon --start --quiet --pidfile $PIDFILE \
and replace it with:
start-stop-daemon --start --quiet -m --pidfile $PIDFILE \
2
In /etc/init.d/darkice find:
stop_server() {
# Stop the process using the wrapper
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec $DAEMON
errcode=$?
add after (with the new line):
rm $PIDFILE
3
In /etc/init.d/darkice find:
running() {
# Check if the process is running looking at /proc
# (works for all users)
add after (with the new line):
sleep 1
4
In /etc/default/darkice check that you have
RUN=yes
5
Add default user nobody to the audio group (in my case, to work with ALSA):
adduser nobody audio
or change user to whoever you need in /etc/default/darkice.
6
Fix upstart problem (it seems Darkice is trying to start on boot too early):
update-rc.d -f darkice remove
update-rc.d darkice defaults 99
That's it! I have Darkice, controlled by upstart scripts (service darkice start/stop) running on boot.
Appendix
/etc/init.d/darkice diff:
86c86
<
---
> sleep 1
96c96
< start-stop-daemon --start --quiet --pidfile $PIDFILE \
---
> start-stop-daemon --start --quiet -m --pidfile $PIDFILE \
106a107
> rm $PIDFILE
184d184
<
/etc/init.d/darkice full code:
#!/bin/sh
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
# Copyright (c) 2009 Jochen Friedrich <jochen@scram.de>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License with
# the Debian operating system, in /usr/share/common-licenses/GPL; if
# not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
#
### BEGIN INIT INFO
# Provides: darkice
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Live audio streamer
# Description: DarkIce is an IceCast, IceCast2 and ShoutCast
# live audio streamer.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=darkice
DAEMON=/usr/bin/$NAME
DESC="Live audio streamer"
LOGDIR=/var/log
USER=nobody
GROUP=nogroup
PIDFILE=/var/run/$NAME.pid
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
# Default options, these can be overriden by the information
# at /etc/default/$NAME
DAEMON_OPTS="" # Additional options given to the server
DIETIME=2 # Time to wait for the server to die, in seconds
# If this value is set too low you might not
# let some servers to die gracefully and
# 'restart' will not work
# Include defaults if available
if [ -f /etc/default/$NAME ] ; then
. /etc/default/$NAME
fi
# Use this if you want the user to explicitly set 'RUN' in
# /etc/default/
if [ "x$RUN" != "xyes" ] ; then
exit 0
fi
set -e
running_pid() {
# Check if a given process pid's cmdline matches a given name
pid=$1
name=$2
[ -z "$pid" ] && return 1
[ ! -d /proc/$pid ] && return 1
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
# Is this the expected server
[ "$cmd" != "$name" ] && return 1
return 0
}
running() {
# Check if the process is running looking at /proc
# (works for all users)
sleep 1
# No pidfile, probably no daemon present
[ ! -f "$PIDFILE" ] && return 1
pid=`cat $PIDFILE`
running_pid $pid $DAEMON || return 1
return 0
}
start_server() {
# Start the process using the wrapper
start-stop-daemon --start --quiet -m --pidfile $PIDFILE \
--background --chuid $USER:$GROUP --exec $DAEMON -- $DAEMON_OPTS
errcode=$?
return $errcode
}
stop_server() {
# Stop the process using the wrapper
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec $DAEMON
errcode=$?
rm $PIDFILE
return $errcode
}
force_stop() {
# Force the process to die killing it manually
[ ! -e "$PIDFILE" ] && return
if running ; then
kill -15 $pid
# Is it really dead?
sleep "$DIETIME"s
if running ; then
kill -9 $pid
sleep "$DIETIME"s
if running ; then
echo "Cannot kill $NAME (pid=$pid)!"
exit 1
fi
fi
fi
rm -f $PIDFILE
}
case "$1" in
start)
log_daemon_msg "Starting $DESC " "$NAME"
# Check if it's running first
if running ; then
log_progress_msg "apparently already running"
log_end_msg 0
exit 0
fi
if start_server && running ; then
# It's ok, the server started and is running
log_end_msg 0
else
# Either we could not start it or it is not running
# after we did
# NOTE: Some servers might die some time after they start,
# this code does not try to detect this and might give
# a false positive (use 'status' for that)
log_end_msg 1
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
if running ; then
# Only stop the server if we see it running
stop_server
log_end_msg $?
else
# If it's not running don't do anything
log_progress_msg "apparently not running"
log_end_msg 0
exit 0
fi
;;
force-stop)
# First try to stop gracefully the program
$0 stop
if running; then
# If it's still running try to kill it more forcefully
log_daemon_msg "Stopping (force) $DESC" "$NAME"
force_stop
log_end_msg $?
fi
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
stop_server
# Wait some sensible amount, some server need this
[ -n "$DIETIME" ] && sleep $DIETIME
start_server
running
log_end_msg $?
;;
status)
log_daemon_msg "Checking status of $DESC" "$NAME"
if running ; then
log_progress_msg "running"
log_end_msg 0
else
log_progress_msg "apparently not running"
log_end_msg 1
exit 1
fi
;;
reload)
log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
log_warning_msg "cannot re-read the config file (use restart)."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
Hope this will help someone. Cheers! ;)
P.S. I am wondering how to propose this changes to the package maintainer. Tnx.