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