github.com/swiftstack/ProxyFS@v0.0.0-20210203235616-4017c267d62f/pfsagentd/main.go (about) 1 // Copyright (c) 2015-2021, NVIDIA CORPORATION. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package main 5 6 import ( 7 "log" 8 "os" 9 "os/signal" 10 11 "golang.org/x/sys/unix" 12 13 "github.com/swiftstack/ProxyFS/conf" 14 ) 15 16 func main() { 17 var ( 18 confMap conf.ConfMap 19 err error 20 signalChan chan os.Signal 21 ) 22 23 if len(os.Args) < 2 { 24 log.Fatalf("no .conf file specified") 25 } 26 27 // Parse arguments (at this point, logging goes only to the console) 28 29 globals.logFile = nil 30 globals.config.LogFilePath = "" 31 globals.config.LogToConsole = true 32 33 confMap, err = conf.MakeConfMapFromFile(os.Args[1]) 34 if nil != err { 35 log.Fatalf("failed to load config: %v", err) 36 } 37 38 err = confMap.UpdateFromStrings(os.Args[2:]) 39 if nil != err { 40 log.Fatalf("failed to apply config overrides: %v", err) 41 } 42 43 // Arm signal handler used to indicate termination and wait on it 44 // 45 // Note: signalled chan must be buffered to avoid race with window between 46 // arming handler and blocking on the chan read 47 48 signalChan = make(chan os.Signal, 1) 49 50 signal.Notify(signalChan, unix.SIGINT, unix.SIGTERM, unix.SIGHUP) 51 52 // Initialize globals 53 54 initializeGlobals(confMap) 55 56 // Trigger initial auth plug-in invocation 57 58 updateAuthTokenAndStorageURL() 59 60 // Perform mount via ProxyFS 61 62 doMountProxyFS() 63 64 // Start serving FUSE mount point 65 66 performMountFUSE() 67 68 // Start serving HTTP 69 70 serveHTTP() 71 72 // Await any of specified signals or fission exit 73 74 select { 75 case _ = <-signalChan: 76 // Normal termination due to one of the above registered signals 77 case err = <-globals.fissionErrChan: 78 // Unexpected exit of fission.Volume 79 logFatalf("unexpected error from package fission: %v", err) 80 } 81 82 // Stop serving HTTP 83 84 unserveHTTP() 85 86 // Stop serving FUSE mount point 87 88 performUnmountFUSE() 89 90 // Flush all dirty fileInode's 91 92 emptyFileInodeDirtyListAndLogSegmentChan() 93 94 // Perform unmount via ProxyFS 95 96 doUnmountProxyFS() 97 98 // Terminate authPlugIn 99 100 stopAuthPlugIn() 101 102 // Uninitialize globals 103 104 uninitializeGlobals() 105 }