ha-hostname
changeset 0 4bc43250587a
child 24 d50c1525cffd
equal deleted inserted replaced
-1:000000000000 0:4bc43250587a
       
     1 #! /bin/sh
       
     2 ### BEGIN INIT INFO
       
     3 # Provides:          hostname
       
     4 # Required-Start:
       
     5 # Required-Stop:
       
     6 # Default-Start:     S
       
     7 # Default-Stop:
       
     8 # Short-Description: Set hostname based on /etc/hostname
       
     9 # Description:       Read the machines hostname from /etc/hostname, and
       
    10 #                    update the kernel value with this value.  If
       
    11 #                    /etc/hostname is empty, the current kernel value
       
    12 #                    for hostname is used.  If the kernel value is
       
    13 #                    empty, the value 'localhost' is used.
       
    14 ### END INIT INFO
       
    15 
       
    16 PATH=/sbin:/bin
       
    17 
       
    18 . /lib/init/vars.sh
       
    19 . /lib/lsb/init-functions
       
    20 
       
    21 do_start () {
       
    22 
       
    23 	# .hs
       
    24 	eval `grep -o '[[:blank:]]hostname=[[:graph:]]\+' /proc/cmdline | tail -1`
       
    25 
       
    26 	if test "$hostname"; then
       
    27 		HOSTNAME="$hostname"
       
    28 	else
       
    29 		[ -f /etc/hostname ] && HOSTNAME="$(cat /etc/hostname)"
       
    30 	fi
       
    31 
       
    32 	# Keep current name if /etc/hostname is missing.
       
    33 	[ -z "$HOSTNAME" ] && HOSTNAME="$(hostname)"
       
    34 
       
    35 	# And set it to 'localhost' if no setting was found
       
    36 	[ -z "$HOSTNAME" ] && HOSTNAME=localhost
       
    37 
       
    38 	[ "$VERBOSE" != no ] && log_action_begin_msg "Setting hostname to '$HOSTNAME'"
       
    39 	hostname "$HOSTNAME"
       
    40 	ES=$?
       
    41 	[ "$VERBOSE" != no ] && log_action_end_msg $ES
       
    42 	exit $ES
       
    43 }
       
    44 
       
    45 case "$1" in
       
    46   start|"")
       
    47 	do_start
       
    48 	;;
       
    49   restart|reload|force-reload)
       
    50 	echo "Error: argument '$1' not supported" >&2
       
    51 	exit 3
       
    52 	;;
       
    53   stop)
       
    54 	# No-op
       
    55 	;;
       
    56   *)
       
    57 	echo "Usage: hostname.sh [start|stop]" >&2
       
    58 	exit 3
       
    59 	;;
       
    60 esac