#!/bin/sh
#
# iproute2fs -- rtnetlink(7) virtual filesystem
#
# chkconfig: - 10 90
# description: \
#       iproute2fs is a virtual filesystem server, that \
#       work over 9P protocol. It can be mounted with \
#       standard mount(8) or FUSE mount commands, you \
#       can also use command line tool ixpc.
# processname: python
# config: 
# pidfile: /var/run/iproute2fs.pid
#
### BEGIN INIT INFO
# Provides: iproute2fs
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:
# Description: rtnetlink(7) virtual filesystem
# Short-Description: mount / umount iproute2fs
### END INIT INFO
#
# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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


SOCKET=/var/run/iproute2fs.sock
MODE=0600
TARGET=/srv/net

PIDFILE=/var/run/iproute2fs.pid
LOCKFILE=/var/lock/subsys/iproute2fs
RETVAL=0

start()
{
    start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- iproute2fs -d -l $SOCKET -p $MODE -P $PIDFILE
    RETVAL=$?
    mkdir -p $TARGET
    mount -t 9p -o unix,trans=unix,name=root,uname=root,noextend,nodev,uid=0,gid=0,dfltuid=0,dfltgid=0 $SOCKET $TARGET
    return $RETVAL
}

stop()
{
    umount $TARGET 2>/dev/null
    stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- python
    RETVAL=$?
    return $RETVAL
}

restart()
{
    stop
    start
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        restart
        ;;
    condstop)
        if [ -e "$LOCKFILE" ]; then
            stop
        fi
        ;;
    condrestart)
        if [ -e "$LOCKFILE" ]; then
            restart
        fi
        ;;
    status)
        status --pidfile "$PIDFILE" --expect-user root -- python
        RETVAL=$?
        ;;
    *)
        msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|status}"
        RETVAL=1
esac

exit $RETVAL
