You are not logged in.
Pages: 1
Recently, I noted that most (but not all) scripts look almost same except they start/stop/restart different daemons. So, if I wanted to create new daemon startup script(ntpd for example), I would copy gpm to ntpd and edit ntpd to fit my needs. In this editing, as a rule of thumb, I need to change five (only five!) things: daemon's full path, it's name as it would appear in echo command, its name as it would apper in add_daemon/rm_daemon sections, full path to a log file(if any), and any options with which a daemon to be runned. After thinking this over couple times, I started to wish to make the process of creating new daemon scripts easier, and this what I got:
Any daemon could have this form:
#!/bin/bash
# /etc/rc.d/this/file's/name
PROG_PATH=/path/to/the/executable
PROG_NAME="This Daemon's Name"
PROG_LOG=/path/to/the/log # Optional
PROG=this_daemon
PROG_OPT='-any -command-line -options' # Optional
# Running the actual script to start/stop/restart this daemon:
. /etc/rc.d/runner $1
# end
For example, my gpm looks like this:
#!/bin/bash
# /etc/rc.d/gpm
PROG_PATH=/usr/sbin/gpm
PROG_NAME="GPM Daemon"
PROG=gpm
PROG_OPT='-m /dev/psaux -t ps2 -3'
. /etc/rc.d/runner $1
# end
The file /etc/rc.d/runner looks like this(and it does not need to be edited at any time, except upgrades)
#!/bin/bash
# /etc/rc.d/runner
. /etc/rc.conf
. /etc/rc.d/functions
PID=`pidof -o %PPID $PROG_PATH`
case "$1" in
start)
stat_busy "Starting $PROG_NAME"
# I could not make scripts work with redirection sign in $PROG_OPT
if [ "$PROG_LOG" = "" ]; then
[ -z "$PID" ] && $PROG_PATH $PROG_OPT
else
[ -z "$PID" ] && $PROG_PATH $PROG_OPT &> $PROG_LOG
fi
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon $PROG
stat_done
fi
;;
stop)
stat_busy "Stopping $PROG_NAME"
[ ! -z "$PID" ] && kill $PID &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon $PROG
stat_done
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0
# end
I did not edit files sshd, network, and nfsmount, because oftheir uniqueness. if you want to check out the scripts, they are at ftp://ftp.archlinux.org/incoming/RouslanScripts.tar.gz. In case if you are curious if this stuff works, the answer is yes, I'm currently using it and there're no problems yet.
I hope this was helpful.
Rouslan
Offline
I thought about this, and liked the thought. Now that you made it, I like it even more :-)
Offline
Pages: 1