mjf.init 2.44 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
18
19
20
#
# 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
#

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

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

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

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

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

        if [ "$total_cpu" == "" ] ; then
Andrew McNab's avatar
Andrew McNab committed
41
42
43
44
45
46
47
48
49
          # If not explicitly configured then try to get it from the batch system
          if [ -x /usr/bin/get-total-cpu ] ; then
            $total_cpu=`/usr/bin/get-total-cpu`
          fi
        
          # 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
50
        fi
51
        echo -n "$total_cpu" > /etc/machinefeatures.tmp/total_cpu
Andrew McNab's avatar
Andrew McNab committed
52
        
53
54
        if [ "$hs06" != "" ] ; then
          echo -n "$hs06" > /etc/machinefeatures.tmp/hs06
Andrew McNab's avatar
Andrew McNab committed
55
56
        fi
        
57
58
        if [ "$shutdowntime" != "" ] ; then
          echo -n "$shutdowntime" > /etc/machinefeatures.tmp/shutdowntime
Andrew McNab's avatar
Andrew McNab committed
59
60
        fi
        
61
62
        if [ "$grace_secs" != "" ] ; then
          echo -n "$grace_secs" > /etc/machinefeatures.tmp/grace_secs
Andrew McNab's avatar
Andrew McNab committed
63
64
        fi

65
66
67
68
        # 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
69
        echo_success
Andrew McNab's avatar
Andrew McNab committed
70
71
72
73
74
75
76
        echo
	return 0
}

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

77
        # Remove /etc/machinefeatures in case of future upgrades
Andrew McNab's avatar
Andrew McNab committed
78
79
80
        echo -n $"Clean up machinefeatures: "
        rm -Rf /etc/machinefeatures
        echo_success
Andrew McNab's avatar
Andrew McNab committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
        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