Jürgen Hötzel wrote:
On Sun, Jun 03, 2007 at 10:10:38PM +0300, Hussam Al-Tayeb wrote:
On Sun, 2007-06-03 at 17:08 +0200, Jürgen Hötzel wrote:
On Sun, Jun 03, 2007 at 04:40:33PM +0200, Kevin Bader wrote:
Nice script, but I don't think such a script is very useful since the order of
the daemons array is important. So it's better to use an editor I guess ;-)
Yes, this script is just appending, which is OK for most services you add.
Implementing order should be easy -> this is left to the reader ;)
Jürgen
_______________________________________________
arch mailing list
[email protected]
http://archlinux.org/mailman/listinfo/arch
I can do the reordering thing. It's not hard. But I would require a
default list of how the ordering should be. If anyone can provide a list
of all the daemons that Archlinux ships and their correct order, I would
much appreciate this.
Unlike other distros, Arch Linux doesn't have dependency information
encoded in init scripts.
I couldn't resist. So I extended my script (inspired by 'chkconfig') do
enable/disable
services and allow ordering:
Usage: daemons.sh [-b daemon] add|remove|enable|disable daemon [daemon]...
If you want to add iptables before network:
daemons.sh -b network add iptables
If you want to disable iptables
daemons.sh disable iptables
Jürgen
talk about not being able to resist :)
I had this service script i've been using forever on my various arch
boxes that does 'service start|restart|status' on /etc/rc.d/foobar.
I've merged in Jurgen's daemons.sh, so this is now much more usefull.
MiniHelp :P
- Just running 'service' will give you a list of all 'running' services
- Running service -a, will give you a list of all services (heh!)
- Running 'service foobar start|restart|status' will do what you expect :)
- Add running 'service foobar enable|disable|add|remove' will also do
what you expect.
- Running 'service -b frumpel foobar add, will add service foobar to
the DAEMONS array before service frumpel
BUG: This doesn't work well with 'background' services... if someone
doesn't beat me to it, i'll extend it to properly support background
services (the @foobar variety i mean)
hehe... nice work Jurgen
Cheers,
Essien
------------------------------------------------------------------------
_______________________________________________
arch mailing list
[email protected]
http://archlinux.org/mailman/listinfo/arch
#!/bin/bash
#service: script to help cut down typing when working with Archlinux daemons :)
#Added add|remove|enable|disable commands from Jurgen's daemons.sh
myver=0.2
SED="sed --in-place"
CONFIG="/etc/rc.conf"
ADD_CMD_BEFORE='' # insert before
#. /etc/rc.conf
. ${CONFIG}
. /etc/rc.d/functions
function daemons_array {
# param 1: command
# param 2: member
local member=${2}
local command=${1}
case "${command}" in
disable)
sed_command="s/DAEMONS=(\([^)]*\)${member}\([^)]*\))/DAEMONS=(\1!${member}\2)/"
;;
enable)
sed_command="s/DAEMONS=(\([^)]*\)!${member}\([^)]*\))/DAEMONS=(\1${member}\2)/"
;;
add)
if [[ ! -e /etc/rc.d/${member} ]]; then
echo /etc/rc.d/${member} does not exist! >&2
return 1
else
# align
if [[ -z "${ADD_CMD_BEFORE}" ]]; then
member=" ${member}"
else
member="${member} "
fi
sed_command="s/DAEMONS=(\([^)]*\)\(${ADD_CMD_BEFORE}[^)]*\))/DAEMONS=(\1${member}\2)/"
fi
;;
remove)
sed_command="s/DAEMONS=(\([^)]*\)\([[:space:]]${member}\|${member}[[:space:]]\)\([^)]*\))/DAEMONS=(\1\3)/"
;;
esac
${SED} -e "${sed_command}" ${CONFIG}
}
stat_alive() {
deltext
echo -e " $C_OTHER[${C_DONE}LIVE$C_OTHER]$C_CLEAR "
}
stat_dead() {
deltext
echo -e " $C_OTHER[${C_FAIL}DEAD$C_OTHER]$C_CLEAR "
}
function daemon_runner() {
command=$1
daemon_name=$2
DAEMON_CONTROL_PATH=/etc/rc.d
$DAEMON_CONTROL_PATH/$daemon_name $command
}
function ls_strip() {
_dir=$1
ls -l $_dir | grep ":" | sed -r s/\ +/\ /g | cut -d' ' -f8
}
function show_running() {
ls_strip "/var/run/daemons"
}
function show_all() {
ls_strip "/etc/rc.d"
}
function daemon_get_status() {
_daemon=$1
stat_busy "$_daemon status"
ls_strip "/var/run/daemons" | grep $_daemon >/dev/null 2>/dev/null
if [ $? -gt 0 ]; then
stat_dead
else
stat_alive
fi
}
function usage() {
cmdname=$(basename $0)
echo "$cmdname version $myver"
echo "usage: $cmdname [options] <daemonname>
start|stop|status|restart|add|remove|enable|disable"
echo "options:"
echo " -a List [a]ll daemons"
echo " -b <daemon> Add <daemonname> [b]efore <daemon>"
echo " -r List all [r]unning daemons"
echo
echo " if no argument is specified, assumes -r"
echo
exit
}
if [ $# != "0" ];then
case $1 in
-*) while getopts ":ab:r" opt;do
case "$opt" in
a) show_all
exit
;;
b) ADD_CMD_BEFORE="$OPTARG"
shift 2
;;
r) show_running
exit
;;
?) usage
;;
esac
done
;;
esac
case $2 in
start) daemon_runner start $1
;;
stop) daemon_runner stop $1
;;
restart) daemon_runner restart $1
;;
status) daemon_get_status $1
;;
enable) daemons_array enable $1
;;
disable) daemons_array disable $1
;;
background) daemons_array background $1
;;
remove) daemons_array remove $1
;;
add) daemons_array add $1
;;
*) usage
esac
else
show_running
fi
_______________________________________________
arch mailing list
[email protected]
http://archlinux.org/mailman/listinfo/arch