summaryrefslogtreecommitdiff
path: root/community/preload/rc.d
blob: a3cb01ba09d2424ca19565b79e572929c595f092 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
#
#	/etc/rc.d/init.d/preload
#
# Starts the preload daemon
#
# Heavily modified for Arch Linux by Leslie P. Polzer <polzer@gnu.org>.

. /etc/rc.conf
. /etc/rc.d/functions

PID=`pidof -o %PPID /usr/sbin/preload`

if [ -f /etc/conf.d/preload ]; then
        . /etc/conf.d/preload
fi

MIN_MEMORY=${MIN_MEMORY:-256}
# Check for > MIN_MEMORY MB
free -m | awk '/Mem:/ {exit ($2 >= ('"$MIN_MEMORY"'))?0:1}' || exit 0

RETVAL=0

#
# See how we were called.
#

start() {
        if [ -z "$PID" ]; then
                stat_busy "Starting preload daemon: "
                /usr/sbin/preload $PRELOAD_OPTS
                RETVAL=$?
                if [ $RETVAL -eq 0 ]; then
			if [ -n $IONICE_OPTS ]; then
				/usr/bin/ionice $IONICE_OPTS -p "`pidof -o %PPID /usr/sbin/preload`"
			fi
                        add_daemon preload
                        stat_done
                else
                        stat_fail
                fi
        fi
        return $RETVAL
}

stop() {
        stat_busy "Stopping preload daemon: "
        kill $PID &>/dev/null
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
                rm_daemon preload
                stat_done
		PID=""
        else
                stat_fail
        fi
        return $RETVAL
}


restart() {
        $0 stop
	sleep 1
        $0 start
}	

reload() {
        trap "" SIGHUP
        kill -HUP $PID
}	

case "$1" in
        start)
        start
        ;;
        stop)
        stop
        ;;
        reload)
        reload
        ;;
        restart)
        restart
        ;;
        condrestart)
        if [ ! -z $PID ]; then
                restart
        else
                stat_fail
        fi
        ;;
        *)
        echo "Usage: $0 {start|stop|restart|condrestart|reload}"
        exit 1
esac

exit $RETVAL