Whamcloud - gitweb
cafb07b43581b6d75049476fa9472e700b10575d
[fs/lustre-release.git] / lustre / conf / resource / Lustre
1 #!/bin/sh
2 #
3 # License:      GNU General Public License (GPL)v2
4 # Description:  Manages Lustre server on a shared storage
5 # Written by:   Gabriele Paciucci, Nathaniel Clark
6 # Release Date: 28 February 2017
7 # Release Version: 1.0.1
8 # Copyright (c) 2017, Intel Corporation
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms and conditions of the GNU General Public License,
12 # version 2, as published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
18 #
19 #
20 # usage: ./Lustre {start|stop|status|monitor|validate-all|meta-data}
21 #
22 #               OCF parameters are as follows:
23 #               OCF_RESKEY_target - the device or ZFS volume to mount/umount
24 #               OCF_RESKEY_mountpoint - the mountpoint to use
25 #######################################################################
26 # Initialization:
27
28 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
29 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
30
31
32 # Variables used by multiple methods
33
34
35 #######################################################################
36
37 # USAGE
38
39 usage() {
40     echo "usage: $0 {start|stop|status|monitor|validate-all|meta-data}"
41 }
42
43 # META-DATA
44
45 meta_data() {
46     cat <<END
47 <?xml version="1.0"?>
48 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
49 <resource-agent name="Lustre">
50 <version>1.0.1</version>
51 <longdesc lang="en">
52 This script manages Lustre Targets (MGT, MDT, OST).
53 The script is able to mount/umount Lustre Targets.
54
55 The standard monitor operation of depth 0 (also known as probe)
56 checks if the filesystem is mounted and lustre is healthy
57 </longdesc>
58 <shortdesc lang="en">Lustre management</shortdesc>
59
60 <parameters>
61
62 <parameter name="target" unique="1" required="1">
63 <longdesc lang="en">
64 The name of the target created during the Lustre format
65 (e.g. /dev/sda, ZPOOL/MGS, /dev/mapper/mpatha)
66 </longdesc>
67 <shortdesc lang="en">Lustre target name</shortdesc>
68 <content type="string" default="" />
69 </parameter>
70
71 <parameter name="mountpoint" unique="1" required="1">
72 <longdesc lang="en">
73 The mount point where the Lustre target will be mounted.
74 </longdesc>
75 <shortdesc lang="en">Mount point for Lustre</shortdesc>
76 <content type="string" default="" />
77 </parameter>
78
79 </parameters>
80
81 <actions>
82 <action name="start"   timeout="300s" />
83 <action name="stop"    timeout="300s" />
84 <action name="monitor" depth="0"  timeout="300s" interval="20s" />
85 <action name="validate-all"  timeout="30s" />
86 <action name="meta-data"  timeout="5s" />
87 </actions>
88 </resource-agent>
89 END
90     exit $OCF_SUCCESS
91 }
92
93 #####################################################################
94 # STATUS
95 #
96
97 lustre_is_mounted () {
98     # Verify if this is consistent, check pointpoint and filesystem
99     # against source (i.e. device)
100     local dev=$(findmnt -t lustre -ln -o SOURCE -T $(realpath "$OCF_RESKEY_mountpoint"))
101
102     [ -n "$dev" ] &&
103     [ "$dev" == "$OCF_RESKEY_target" -o "$dev" == $(realpath "$OCF_RESKEY_target") ]
104 }
105
106 lustre_monitor () {
107     if ! lustre_is_mounted; then
108         ocf_log err "$OCF_RESKEY_target is not mounted"
109         return $OCF_NOT_RUNNING
110     fi
111
112     # TODO: Add better status monitoring
113     return $OCF_SUCCESS
114 }
115
116 #####################################################################
117 # ACTIONS
118 #
119
120 lustre_mount () {
121     if ! lustre_is_mounted; then
122         ocf_log info "Starting to mount $OCF_RESKEY_target"
123
124         if mount -t lustre $OCF_RESKEY_target $OCF_RESKEY_mountpoint ; then
125             ocf_log info "$OCF_RESKEY_target mounted successfully"
126             return $OCF_SUCCESS
127         fi
128         ocf_log err "$OCF_RESKEY_volume mount failed"
129         return $OCF_ERR_GENERIC
130     fi
131     return $OCF_SUCCESS
132 }
133
134 lustre_umount () {
135     if lustre_is_mounted; then
136         ocf_log info "Starting to unmount $OCF_RESKEY_target"
137
138         if umount $OCF_RESKEY_mountpoint; then
139             ocf_log info "$OCF_RESKEY_target unmounted successfully"
140             return $OCF_SUCCESS
141         fi
142         ocf_log err "$OCF_RESKEY_target unmount failed"
143         return $OCF_ERR_GENERIC
144     fi
145     return $OCF_SUCCESS
146 }
147
148 all_start () {
149     lustre_mount
150     mnt_success=$?
151     if [ "$mnt_success" != "$OCF_SUCCESS" ]; then
152         ocf_log err "$OCF_RESKEY_target can not be mounted with this error: $mnt_success"
153         return $OCF_ERR_GENERIC
154     fi
155     return $OCF_SUCCESS
156 }
157
158 all_stop () {
159     lustre_umount
160     mnt_success=$?
161     if [ "$mnt_success" != "$OCF_SUCCESS" ]; then
162         ocf_log err "$OCF_RESKEY_target can not be unmounted with this error: $mnt_success"
163         return $OCF_ERR_GENERIC
164     fi
165     return $OCF_SUCCESS
166 }
167
168 validate () {
169     if [ ! -d "$(realpath $OCF_RESKEY_mountpoint)" ]; then
170         ocf_log err "$OCF_RESKEY_mountpoint can not be found"
171         return $OCF_ERR_INSTALLED
172     fi
173     if ! modinfo -n lustre >/dev/null 2>&1; then
174         ocf_log err "lustre module not available"
175         return $OCF_ERR_INSTALLED
176     fi
177     return $OCF_SUCCESS
178 }
179
180 case $1 in
181     meta-data)          meta_data;;
182     start)              all_start;;
183     stop)               all_stop;;
184     status|monitor)     lustre_monitor;;
185     validate-all)       validate;;
186     usage)              usage
187         exit $OCF_SUCCESS
188         ;;
189     *)                  exit $OCF_ERR_UNIMPLEMENTED;;
190 esac