summaryrefslogtreecommitdiff
path: root/scripts/rl-system.init
blob: a08095a1e0055cc92fbb629cbd1f091375b909b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
# **** License ****
# Version: VPL 1.0
#
# The contents of this file are subject to the Vyatta Public License
# Version 1.0 ("License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.vyatta.com/vpl
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# This code was originally developed by Vyatta, Inc.
# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
# All Rights Reserved.
#
# Author:	Tom Grennan <tgrennan@vyatta.com>
# Description:	Vyatta Router system setup
#		this is an indirect init sub-script executed by ofr.init
#
# **** End License ****

progname=${0##*/}
ACTION=$1

source /etc/default/vyatta

: ${vyatta_prefix:=/opt/vyatta}
: ${vyatta_bindir:=${vyatta_prefix}/bin}
: ${vyatta_sbindir:=${vyatta_prefix}/sbin}
: ${vyatta_sysconfdir:=${vyatta_prefix}/etc}
: ${hostname:=`hostname -s`}

[[ $PATH == *${vyatta_bindir}* ]] || PATH+=:${vyatta_bindir}
[[ $PATH == *${vyatta_sbindir}* ]] || PATH+=:${vyatta_sbindir}

export PATH

. /lib/lsb/init-functions

## BOOTFILE is provided by ofr.init
: ${BOOTFILE:=$prefix/etc/config/config.boot}

if [ -z "$LOGFILE" ] ; then
    if touch /var/log/messages &> /dev/null ; then
	LOGFILE=/var/log/messages
    else
	LOGFILE=/dev/null
    fi
fi

syslog ()
{
    logger -p user.warning -t "$progname" "$*"
}

shopt -s extglob nullglob

search_config_if_wan () {
    grep "\<serial\>.*\<$1\>" $BOOTFILE >/dev/null
}

add_new_serial_if () {
    __config_additions=/tmp/__config_additions
    rm -f $__config_additions
    ip link show |
    sed -n '/^[0-9]*: wan[0-9]*:/ s/.* \([^:]*\):.*$/\1/p' |
    while read wan ; do
	if ! search_config_if_wan $wan ; then
	    echo "    serial $wan" >> $__config_additions
	fi
    done
    if [ -e $__config_additions ]; then
	rm -f /tmp/__bootfile
	sed '/^interfaces {$/ r '$__config_additions \
	    $BOOTFILE > /tmp/__bootfile
	mv /tmp/__bootfile $BOOTFILE
	rm -f $__config_additions
    fi
}

proc_flags ()
{
    # reset_promiscous_arp_response
    echo 1 > /proc/sys/net/ipv4/conf/default/arp_filter 
    # set_ip_forwarding
    echo 1 > /proc/sys/net/ipv4/ip_forward

    # if a primary address is removed from an interface promote and
    # secondary available
    echo 1 > /proc/sys/net/ipv4/conf/all/promote_secondaries

    # set maximum rmem_max to accomodate netlink buffers
    echo 223232 > /proc/sys/net/core/rmem_max
}

## Update the version information
update_version_info () {
    if [ -f ${vyatta_sysconfdir}/version.master ]; then
	cp ${vyatta_sysconfdir}/version.master ${vyatta_sysconfdir}/version
    fi
}

## Clear out apt config file--it will be filled in by rtrmgr
clear_apt_config()
{
    cat /dev/null >/etc/apt/sources.list || true
}

## snmp should be a separate package,
## but for now load the kernel module here
add_snmp_stats_module()
{
    modprobe ipt_rlsnmpstats || true
}

set_reboot_on_panic()
{
    echo 1 > /proc/sys/kernel/panic_on_oops
    echo 60 > /proc/sys/kernel/panic
}

clear_or_override_config_files ()
{
    for conf in ntp.conf \
        snmp/snmpd.conf snmp/snmptrapd.conf keepalived/keepalived.conf \
        ipvsadm.rules default/ipvsadm resolv.conf
    do
	if [ -f /etc/$conf ] ; then
	    cat /dev/null > /etc/$conf || true
	fi
    done
    # ssh v1. remove the empty key file
    rm -f /etc/ssh/ssh_host_key
}

udev_rescan ()
{
    rm -f /tmp/vyatta_net_name_*
    udevtrigger --subsystem-match=net && udevsettle
    for ff in /tmp/vyatta_net_name_* ; do
	f=${ff##*/}
	cmd_name_hwid=${f/vyatta_net_name_/}
	cmd=${cmd_name_hwid%%_*}
	name_hwid=${cmd_name_hwid#*_}
	name=${name_hwid%_*}
	hwid=${name_hwid#*_}
	syslog $cmd $name $hwid
	$vyatta_sbindir/${cmd}_bootfile_eth_hwid $BOOTFILE $name $hwid
    done
}

start () {
    udev_rescan
    clear_or_override_config_files || \
	log_failure_msg "can\'t reset config files"
    set_reboot_on_panic || \
	log_failure_msg "can\'t set reboot on panic"
    add_new_serial_if || \
	log_failure_msg "can\'t add serial interfaces"
    proc_flags  || \
	log_failure_msg "can\'t reset proc flags"
    update_version_info
    clear_apt_config
    add_snmp_stats_module
}

case "$ACTION" in
    start) start ;;
    stop|restart|force-reload) true ;; # nothing to stop/restart
    *)	log_failure_msg "action unknown: $ACTION" ;
	false ;;
esac

exit $?

# Local Variables:
# mode: shell-script
# sh-indentation: 4
# End: