#6 init.d script for RedHat Linux

open
nobody
None
5
2002-03-26
2002-03-26
No

Here is the /etc/init.d/ser2net script that I use
to automatically start of set2net at boot time.

#!/bin/sh
#
# ser2net Serial to network proxy
#
# chkconfig: 2345 89 3
# description: Serial to network proxy

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

SET2NET=/usr/local/sbin/ser2net
CFG=/etc/ser2net.conf

# firewall
#
if [ ! -f "$SET2NET" ]; then
exit 0
fi
if [ ! -x "$SET2NET" ]; then
echo "$0: not executable: $SET2NET" 1>&2
exit 0
fi
if [ ! -f "$CFG" ]; then
echo "$0: missing config file: $CFG" 1>&2
exit 0
fi

RETVAL=0

# See how we were called.
case "$1" in
start)
# Start daemons.
echo -n "Starting ser2net: "
daemon $SET2NET -p 9999
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ser2net
;;
stop)
# Stop daemons.
echo -n "Shutting down ser2net: "
# killproc does not deal with the multiple ser2net's in some versions
PIDS="`pidof -o $$ -o $PPID -o %PPID $SET2NET`"
if [ -n "$PIDS" ]; then
kill -9 $PIDS 2>&1 | grep -v 'No such pid'
PIDS="`pidof -o $$ -o $PPID -o %PPID $SET2NET`"
if [ -n "$PIDS" ]; then
RETVAL=2 # some ser2net did not die
else
RETVAL=0 # we killed off all of the ser2net's
fi
else
RETVAL=1 # no ser2net's to kill
fi
case "$RETVAL" in
0) rm -f /var/lock/subsys/ser2net
success "Pre-stop ser2net -"
;;
1) rm -f /var/lock/subsys/ser2net
passed "Pre-stop ser2net -"
;;
*) failure "Pre-stop ser2net -"
;;
esac
echo
;;
status)
status ser2net
RETVAL=$?
;;
restart|reload)
$0 stop
$0 start
RETVAL=$?
;;
*)
echo "Usage: ser2net {start|stop|restart|status}"
exit 4
esac

exit $RETVAL

Discussion

  • Logged In: YES
    user_id=34397

    I'll attach a file so that the formatting is not so bad.
    I should have done this in the first place ... sorry!

     
  • RedHat /etc/rc.d/init.d/ser2net startup file

     
    Attachments
  • Logged In: YES
    user_id=34397

    Download the attached file:

    http://sourceforge.net/tracker/download.php?group_id=28625&atid=393783&file_id=81852&aid=535183

    and place it in /etc/rc.d/init.d/ser2net. Now do:

    chkconfig ser2net reset

    A chkconfig --list ser2net will show that the ser2net
    startup file is
    ready to go:

    ser2net 0:off 1:off 2:on 3:on 4:on 5:on
    6:off

    You can manually start, stop and ser2net:

    service ser2net start
    service ser2net stop
    service ser2net restart

    The ser2net start script defaults to using:

    CONFIG=/etc/ser2net.conf
    CONTROL_PORT="127.0.0.1,9999"

    That is, the control port is 9999 and listens to only
    localhost AND
    the config is in /etc/ser2net.con file.

    You can override these defaults using the RedHat /etc/sysconfig
    method. For example, if you create the file:

    /etc/sysconfig/ser2net

    and place in it, the lines:

    CONFIG=/usr/local/etc/ser2net.conf
    CONTROL_PORT="127.0.0.1,9000"
    SER2NET_OPTIONS="-b"

    You will cause ser2net to start with:

    ser2net -p 127.0.0.1 9000 -c /usr/local/etc/ser2net.conf -n