summaryrefslogtreecommitdiffstats
path: root/sbin/init.d/system
blob: fac0bc3ac609ea4673eb56795a14597b9699a6f0 (plain) (blame)
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
#!/bin/bash

. `dirname $0`/functions

option	hostname	standard_option
option	modprobe 	multiple_option
option	sysctl		multiple_option
option	file_max	standard_option
option	rtc		standard_option	"local"		# "local", "utc", "disabled"
option	rtc_mode	standard_option	"direct"	# "direct", "kernel"

function do_start {
    local svcname=$1
    local instname=$2
    local arg
    local rtc_opt=""

    arg=0
    while [ $arg -lt ${#opt_modprobe[*]} ]; do
	modprobe ${opt_modprobe[$arg]} || return 1
	arg=$[$arg+1]
    done
   
    if [ -n "$opt_file_max" ]; then
	echo $opt_file_max > /proc/sys/fs/file-max
    fi
   
    if [ -n "$opt_hostname" ] ; then
	echo "Setting hostname '$opt_hostname'"
	echo ${opt_hostname%%.*} >/proc/sys/kernel/hostname
	echo ${opt_hostname#*.} >/proc/sys/kernel/domainname
    fi

    # this is necessary because some PCs (eg: siemens) hang otherwise.
    if [ "$opt_rtc_mode" = "direct" ]; then
	rtc_opt="$rtc_opt --directisa"
    fi

    if [ "$opt_rtc" = "utc" ]; then
	echo -n "Setting system time from hardware clock (UTC)... "
	hwclock --hctosys --utc $rtc_opt
	echo "Done."
    elif [ "$opt_rtc" = "local" ]; then
	echo -n "Setting system time from hardware clock (Local time)... "
	hwclock --hctosys --localtime $rtc_opt
	echo "Done."
    fi

    for arg in ${opt_sysctl[*]}; do
	local sysctl value
	sysctl=${arg%%=*}
	sysctl=${sysctl//.//}
	value=${arg##*=}
	if [ -e "/proc/sys/$sysctl" ]; then
	    echo $value > /proc/sys/$sysctl
	else
	    echo "Non-existent sysctl entry : $arg"
	fi
    done
    return 0
}

function do_status {
    local instname=$2
    echo "System status :"
    echo -n "Hostname : "; hostname
    echo "Modules list :"; lsmod
    return 0
}


function do_stop {
    local svcname=$1
    local instname=$2

    arg=${#opt_modprobe[*]}
    while [ $arg -gt 0 ]; do
	arg=$[$arg-1]
	rmmod -r ${opt_modprobe[$arg]} >/dev/null 2>&1
    done

    if [ "$opt_rtc" = "utc" ]; then
	echo -n "Saving system time to hardware clock (UTC)... "
	hwclock --systohc --utc
	echo "Done."
    elif [ "$opt_rtc" = "local" ]; then
	echo -n "Saving system time to hardware clock (Local time)... "
	hwclock --systohc --localtime
	echo "Done."
    fi

    return 0
}

function do_check {
    local svcname=$1
    local instname=$2
    
    read uptime idletime < /proc/uptime
    echo "$HOSTNAME $svcname.$instname $(date +%s) RUNNING ${uptime%%.*} OK"
}

load_config