mjf.init 2.94 KB
Newer Older
Andrew McNab's avatar
Andrew McNab committed
1
2
#!/bin/bash
#
Andrew McNab's avatar
Andrew McNab committed
3
# mjf		Create /etc/machinefeatures files
Andrew McNab's avatar
Andrew McNab committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#
# chkconfig: 345 90 10
# description: Create /etc/machinefeatures files following the Machine/Job Features specification in HSF-TN-2016-02

# Source function library.
. /etc/init.d/functions

#
# Set the following variables in the configuration files
# to set/override them when populating /etc/machinfeatures
# - total_cpu
# - hs06
# - shutdowntime
# - grace_secs
18
# - db12
Andrew McNab's avatar
Andrew McNab committed
19
20
21
#

# Persistent configuration goes in sysconfig
Andrew McNab's avatar
Andrew McNab committed
22
23
if [ -f /etc/sysconfig/mjf ] ; then
  . /etc/sysconfig/mjf
Andrew McNab's avatar
Andrew McNab committed
24
fi
Andrew McNab's avatar
Andrew McNab committed
25
26

# Transient configuration goes in run - for example shutdowntime
27
# Files put in mjf get deleted when the machine boots up!
Andrew McNab's avatar
Andrew McNab committed
28
29
if [ -f /var/run/mjf ] ; then
  . /var/run/mjf
Andrew McNab's avatar
Andrew McNab committed
30
fi
Andrew McNab's avatar
Andrew McNab committed
31
32
33
34

start() {
	[ "$EUID" != "0" ] && exit 1

35
        # Create new files in temporary directory
Andrew McNab's avatar
Andrew McNab committed
36
        echo -n $"Set up /etc/machinefeatures: "
Andrew McNab's avatar
00.02    
Andrew McNab committed
37

38
39
        /bin/rm -Rf /etc/machinefeatures.tmp
        mkdir -p /etc/machinefeatures.tmp
Andrew McNab's avatar
Andrew McNab committed
40
41

        if [ "$total_cpu" == "" ] ; then
Andrew McNab's avatar
Andrew McNab committed
42
          # If not explicitly configured then try to get it from the batch system
43
44
          if [ -x /usr/sbin/mjf-get-total-cpu ] ; then
            total_cpu=`/usr/sbin/mjf-get-total-cpu`
Andrew McNab's avatar
Andrew McNab committed
45
46
          fi
        
47
48
49
50
51
          # If still not explicitly configured then get it from /etc/db12 if available
          if [ "$total_cpu" == "" -a -f /etc/db12/total_cpu ] ; then
            total_cpu=`cat /etc/db12/total_cpu`
          fi

Andrew McNab's avatar
Andrew McNab committed
52
53
54
55
          # If still not explicitly configured then it get from the OS
          if [ "$total_cpu" == "" ] ; then
            total_cpu=`grep '^processor[[:space:]]*:' /proc/cpuinfo | wc --lines`
          fi
Andrew McNab's avatar
Andrew McNab committed
56
        fi
57
        echo -n "$total_cpu" > /etc/machinefeatures.tmp/total_cpu
Andrew McNab's avatar
Andrew McNab committed
58
        
59
60
        if [ "$hs06" != "" ] ; then
          echo -n "$hs06" > /etc/machinefeatures.tmp/hs06
Andrew McNab's avatar
Andrew McNab committed
61
62
        fi
        
63
64
65
66
67
68
69
70
71
        # If not explicitly configured then get from /etc/db12
        if [ "$db12" == "" -a -f /etc/db12/db12 ] ; then
          db12=`cat /etc/db12/db12`
        fi

        if [ "$db12" != "" ] ; then
          echo -n "$db12" > /etc/machinefeatures.tmp/db12
        fi
        
72
73
        if [ "$shutdowntime" != "" ] ; then
          echo -n "$shutdowntime" > /etc/machinefeatures.tmp/shutdowntime
Andrew McNab's avatar
Andrew McNab committed
74
75
        fi
        
76
77
        if [ "$grace_secs" != "" ] ; then
          echo -n "$grace_secs" > /etc/machinefeatures.tmp/grace_secs
Andrew McNab's avatar
Andrew McNab committed
78
79
        fi

80
81
82
83
        # Remove any existing directory and move new version into place
        /bin/rm -Rf /etc/machinefeatures
        /bin/mv -f /etc/machinefeatures.tmp /etc/machinefeatures

Andrew McNab's avatar
Andrew McNab committed
84
        echo_success
Andrew McNab's avatar
Andrew McNab committed
85
86
87
88
89
90
91
        echo
	return 0
}

stop() {
	[ "$EUID" != "0" ] && exit 3

92
        # Remove /etc/machinefeatures in case of future upgrades
Andrew McNab's avatar
Andrew McNab committed
93
94
95
        echo -n $"Clean up machinefeatures: "
        rm -Rf /etc/machinefeatures
        echo_success
Andrew McNab's avatar
Andrew McNab committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
        echo
	return 0
}

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