aboutsummaryrefslogtreecommitdiffstats
path: root/lsb-bootscripts/etc/init.d/localnet
blob: 322bb874972eff66d57d588952405243a0e9bf17 (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
#!/bin/sh
# Begin /etc/init.d/localnet

### BEGIN INIT INFO
# Provides:            localnet
# Required-Start:      $local_fs
# Should-Start:
# Required-Stop:
# Should-Stop:
# Default-Start:       S
# Default-Stop:        0 6
# Short-Description:   Starts the local network.
# Description:         Sets the hostname of the machine and starts the 
#                      loopback interface.
# X-LFS-Provided-By:   LFS
### END INIT INFO

. /lib/lsb/init-functions

case "${1}" in
    start)
        ip addr add 127.0.0.1/8 label lo dev lo
        ip link set lo up
        if [ "${?}" -eq "0" ]
                then
                     log_success_msg "Bringing up the loopback interface..."
                else
                     log_failure_msg "Bringing up the loopback interface..."
                fi

        hostname "${HOSTNAME}"
        if [ "${?}" -eq "0" ]
                then
                     log_success_msg "Setting hostname to ${HOSTNAME}..."
                else
                     log_failure_msg "Setting hostname to ${HOSTNAME}..."
                fi

        ;;

    stop)
        ip link set lo down
        if [ "${?}" -eq "0" ]
                then
                     log_success_msg "Bringing down the loopback interface..."
                else
                     log_failure_msg "Bringing down the loopback interface..."
                fi

        ;;

    restart)
        ip link set lo down
                retval="${?}"
                sleep 1
        ip addr add 127.0.0.1/8 label lo dev lo
                retval=$(( "${retval}" + "${?}" ))
                ip link set lo up
                retval=$(( "${retval}" + "${?}" ))
                hostname "${HOSTNAME}"
                retval=$(( "${retval}" + "${?}" ))
                if [ "${retval}" -eq "0" ]
                then
                    log_success_msg "Restarting local network..."
                else
                    log_failure_msg "Restarting local network..."
                fi
        ;;

    status)
        log_success_msg "Hostname is: ${INFO}$(hostname)${NORMAL}"
        ip link show lo
        ;;

    *)
        echo "Usage: ${0} {start|stop|restart|status}"
        exit 1
        ;;
esac

# End /etc/init.d/localnet