aboutsummaryrefslogtreecommitdiff
path: root/system/preload/rc.preload
blob: efe8802a2fa0b484f2670dd914da8f55be0bcd41 (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
#!/bin/sh

# /etc/rc.d/rc.preload

# See preload(8) for options
PRELOAD_OPTS="-c /etc/preload.conf -s /var/lib/preload/preload.state -l /var/log/preload.log"

# You need at least 256 MB of memory for this to be useful
free -m | awk '/Mem:/ {exit ($2 >= ('256'))?0:1}' || exit 1

start() {
  if [ -x /usr/sbin/preload ]; then
    if [ ! -f /var/run/preload/preload.lock ]; then
      echo "Starting preload daemon: /usr/sbin/preload "
      /usr/sbin/preload $PRELOAD_OPTS && \
      touch /var/run/preload/preload.lock
    else 
      echo "/usr/sbin/preload is already running. Exiting."
      exit 1
    fi
  else
    echo "/usr/sbin/preload is either not present or not executable."
    echo "Exiting."
    exit 1
  fi
}

stop() {
	echo "Stopping preload daemon... "
	killall -9 preload
	rm -f /var/run/preload/preload.lock
}

restart() {
	stop
	sleep 1
	start
}	

reload() {
	trap "" SIGHUP
	killall -HUP preload
}	

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