1#!/bin/sh
2#
3# chkconfig: 2345 08 92
4# description:	Starts and stops racoon and loads IPSec SPD's
5#
6# config: /etc/sysconfig/ipsec.spd
7# config: /etc/racoon/racoon.conf
8
9# Contributed by Kimmo Koivisto <kimmo.koivisto@surfeu.fi>
10# Tested with Fedora C1
11
12# Source function library.
13. /etc/init.d/functions
14
15RACOON=/usr/sbin/racoon
16SETKEY=/sbin/setkey
17IPSEC_SPD=/etc/sysconfig/ipsec.spd
18VAR_SUBSYS_IPSEC=/var/lock/subsys/ipsec
19
20if [ ! -x /usr/sbin/$RACOON ]; then
21    echo -n $"/usr/sbin/$RACOON does not exist."; warning; echo
22    exit 0
23fi
24
25
26start() {
27
28	# Check that SPD-file exists and load it.
29	if [ -f "$IPSEC_SPD" ]; then 
30   		$SETKEY -f $IPSEC_SPD 
31	fi
32	$RACOON
33	touch $VAR_SUBSYS_IPSEC
34}
35
36
37stop() {
38	killall $RACOON 2> /dev/null
39	$SETKEY -FD 
40	$SETKEY -FP 
41        rm -f $VAR_SUBSYS_IPSEC
42}
43
44status() {
45    # Do not print status if lockfile is missing
46
47    if [ ! -f "$VAR_SUBSYS_IPSEC" ]; then
48	echo $"IPSec is stopped."
49	return 1
50    fi
51
52    if [ -f "$VAR_SUBSYS_IPSEC" ]; then
53	echo $"IPSec is started."
54	return 0
55    fi
56}
57
58restart() {
59    stop
60    start
61}
62
63
64
65case "$1" in
66    start)
67	start
68	;;
69    stop)
70	stop
71	;;
72    restart)
73	restart
74	;;
75    condrestart)
76	[ -e "$VAR_SUBSYS_IPSEC" ] && restart
77	;;
78    status)
79	status
80	;;
81    *)
82	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
83	exit 1
84	;;
85esac
86
87exit 0
88