#!/bin/bash ### BEGIN INIT INFO # Provides: vyatta-router # Required-Start: $syslog $time $local_fs # Required-Stop: $syslog $time $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Vyatta Router # Description: Debian init script for the Vyatta Router ### END INIT INFO # **** License **** # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program 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. # # A copy of the GNU General Public License is available as # `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution # or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'. # You can also obtain it by writing to the Free Software Foundation, # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301, USA. # # Author: Tom Grennan # **** End License **** . /lib/lsb/init-functions : ${vyatta_env:=/etc/default/vyatta} source $vyatta_env declare progname=${0##*/} declare action=$1; shift declare -x BOOTFILE=$vyatta_sysconfdir/config/config.boot declare -a subinit declare -a all_subinits=( rl-system firewall ) if [ $# -gt 0 ] ; then for s in $@ ; do [ -x ${vyatta_sbindir}/${s}.init ] && subinit[${#subinit}]=$s done else for s in ${all_subinits[@]} ; do [ -x ${vyatta_sbindir}/${s}.init ] && subinit[${#subinit}]=$s done if [ -x ${vyatta_sbindir}/rtrmgr.init ] ; then subinit+=( rtrmgr ) GROUP=xorp else GROUP=vyattacfg fi fi # check if bootup of this portion is disabled disabled () { grep -q -w novyatta-$1 /proc/cmdline } # if necessary, provide initial config init_bootfile () { if [ -b /dev/fd0 ] && [ ! -d /media/floppy/config ] then [ -d /media/floppy ] || mkdir -p /media/floppy # This mount will try ext2 or fat format # and it will fail if no floppy present # Note: no good way to test for floppy present without causing I/O error mount /dev/fd0 /media/floppy \ -o sync,dirsync,noexec,nodev,noatime,nodiratime,nosuid 2>/dev/null fi [ -d /media/floppy/config ] && mount -o bind /media/floppy/config /opt/vyatta/etc/config if [ -f $BOOTFILE ] && grep -q '/\*XORP Configuration File, v1.0\*/' \ $BOOTFILE >&/dev/null; then CURTIME=$(date +%F-%H%M%S) mv $BOOTFILE $BOOTFILE.pre-glendale.$CURTIME fi if [ ! -r $BOOTFILE ] ; then if [ -f $vyatta_sysconfdir/config.boot.default ]; then cp $vyatta_sysconfdir/config.boot.default $BOOTFILE else $vyatta_sbindir/vyatta_current_conf_ver.pl > $BOOTFILE fi chgrp ${GROUP} $BOOTFILE chmod 660 $BOOTFILE fi if grep -q -x 'rtrmgr {' $BOOTFILE ; then ## remove the unnecessary and potentially conflicting ## config-directory statement (i.e. /mnt/floppy vs. /media/floppy) sed -i '/^rtrmgr {$/,/^}$/d' $BOOTFILE fi } # if necessary, migrate initial config migrate_bootfile () { if [ -x $vyatta_sbindir/vyatta_config_migrate.pl ]; then log_progress_msg migrate $vyatta_sbindir/vyatta_config_migrate.pl $BOOTFILE fi } # load the initial config load_bootfile () { if [ -x $vyatta_sbindir/vyatta-config-loader.pl ]; then log_progress_msg configure sg ${GROUP} -c "$vyatta_sbindir/vyatta-config-loader.pl $BOOTFILE" fi } # Unload the RAID modules that we are not using. It is safe to try to # unload all of the RAID modules. The kernel will refuse to unload any # that we are actually using. # cleanup_raid() { MD_MODULES='linear multipath raid0 raid1 raid456 raid5 raid6 raid10' rmmod $MD_MODULES > /tmp/vyatta_raid_cleanup_log 2>&1 } # # Load the acpi_cpufreq kernel module, but only for certain processors. # Some Intel CPUs need to have it loaded in order to initialize # properly. # load_acpi_cpufreq() { manuf=`dmidecode -s system-manufacturer` prod=`dmidecode -s system-product-name` if [ "$manuf" = "Vyatta" -a "$prod" = "Series 2500" ]; then logger -t "$progname" -p user.notice "loading acpi_cpufreq module" modprobe acpi_cpufreq fi } start () { log_action_begin_msg "Mounting Vyatta Config" mount -o nosuid,nodev,mode=775 -t tmpfs none ${vyatta_configdir} && \ chgrp ${GROUP} ${vyatta_configdir} log_action_end_msg $? disabled bootfile || init_bootfile log_daemon_msg "Starting Vyatta router" disabled migrate || migrate_bootfile for s in ${subinit[@]} ; do if ! disabled $s; then log_progress_msg $s ${vyatta_sbindir}/${s}.init start || (log_end_msg $? && return) fi done disabled configure || load_bootfile load_acpi_cpufreq cleanup_raid chmod g-w,o-w / log_end_msg $? } stop() { local -i status=0 log_daemon_msg "Stopping Vyatta router" for ((i=${#sub_inits[@]} - 1; i >= 0; i--)) ; do s=${subinit[$i]} log_progress_msg $s ${vyatta_sbindir}/${s}.init stop let status\|=$? done log_end_msg $status log_action_begin_msg "Un-mounting Vyatta Config" umount ${vyatta_configdir} log_action_end_msg $? } case "$action" in start) start ;; stop) stop ;; restart|force-reload) stop && start ;; *) log_failure_msg "usage: $progname [ start|stop|restart ] [ subinit ... ]" ; false ;; esac exit $? # Local Variables: # mode: shell-script # sh-indentation: 4 # End: