|
| 1 | +package main |
| 2 | + |
| 3 | +/* |
| 4 | + * Minio Cloud Storage, (C) 2017 Minio, Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +import ( |
| 20 | + "log" |
| 21 | + "os" |
| 22 | + |
| 23 | + "github.com/minio/minio/pkg/madmin" |
| 24 | +) |
| 25 | + |
| 26 | +func main() { |
| 27 | + endpoint := os.Getenv("S3_ADDRESS") |
| 28 | + accessKeyID := os.Getenv("ACCESS_KEY") |
| 29 | + secretAccessKey := os.Getenv("SECRET_KEY") |
| 30 | + useSSL := false |
| 31 | + // check if ENABLE_HTTPS env flag is set. |
| 32 | + if os.Getenv("ENABLE_HTTPS") != "" { |
| 33 | + useSSL = true |
| 34 | + } |
| 35 | + |
| 36 | + madmClnt, err := madmin.New(endpoint, accessKeyID, secretAccessKey, useSSL) |
| 37 | + if err != nil { |
| 38 | + addErrorLog(err.Error()) |
| 39 | + os.Exit(1) |
| 40 | + } |
| 41 | + |
| 42 | + // check the status of the Minio server. |
| 43 | + _, err = madmClnt.ServiceStatus() |
| 44 | + if err != nil { |
| 45 | + addErrorLog(err.Error()) |
| 46 | + os.Exit(1) |
| 47 | + } |
| 48 | + |
| 49 | + // log the success message. |
| 50 | + addRunLog("Target server: " + endpoint + " is reachable. Starting the tests...") |
| 51 | +} |
| 52 | + |
| 53 | +func addErrorLog(message string) { |
| 54 | + errorLogFile := os.Getenv("INIT_ERROR_LOG_FILE") |
| 55 | + file, err := os.OpenFile(errorLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) // For read access. |
| 56 | + if err != nil { |
| 57 | + log.Fatal(err) |
| 58 | + } |
| 59 | + defer file.Close() |
| 60 | + |
| 61 | + // write the log to file |
| 62 | + log.SetOutput(file) |
| 63 | + log.Println(message) |
| 64 | +} |
| 65 | + |
| 66 | +func addRunLog(message string) { |
| 67 | + logFile := os.Getenv("INIT_LOG_FILE") |
| 68 | + file, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) // For read access. |
| 69 | + if err != nil { |
| 70 | + log.Fatal(err) |
| 71 | + } |
| 72 | + defer file.Close() |
| 73 | + |
| 74 | + // write the log to file |
| 75 | + log.SetOutput(file) |
| 76 | + log.Println(message) |
| 77 | +} |
0 commit comments