mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat: improved logging with zerolog
This commit is contained in:
11
go.mod
11
go.mod
@@ -2,16 +2,23 @@ module ironmount
|
||||
|
||||
go 1.24.5
|
||||
|
||||
require (
|
||||
github.com/justinas/alice v1.2.0
|
||||
github.com/rs/zerolog v1.34.0
|
||||
modernc.org/sqlite v1.38.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/rs/xid v1.6.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
|
||||
golang.org/x/sys v0.34.0 // indirect
|
||||
golang.org/x/sys v0.35.0 // indirect
|
||||
modernc.org/libc v1.66.3 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
modernc.org/sqlite v1.38.2 // indirect
|
||||
)
|
||||
|
||||
46
go.sum
46
go.sum
@@ -1,23 +1,65 @@
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/justinas/alice v1.2.0 h1:+MHSA/vccVCF4Uq37S42jwlkvI2Xzl7zTPCN5BnZNVo=
|
||||
github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNEe7i7qA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
|
||||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
|
||||
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
|
||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
|
||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
|
||||
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
|
||||
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
|
||||
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
|
||||
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
|
||||
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
|
||||
modernc.org/cc/v4 v4.26.2 h1:991HMkLjJzYBIfha6ECZdjrIYz2/1ayr+FL8GN+CNzM=
|
||||
modernc.org/cc/v4 v4.26.2/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
||||
modernc.org/ccgo/v4 v4.28.0 h1:rjznn6WWehKq7dG4JtLRKxb52Ecv8OUGah8+Z/SfpNU=
|
||||
modernc.org/ccgo/v4 v4.28.0/go.mod h1:JygV3+9AV6SmPhDasu4JgquwU81XAKLd3OKTUDNOiKE=
|
||||
modernc.org/fileutil v1.3.8 h1:qtzNm7ED75pd1C7WgAGcK4edm4fvhtBsEiI/0NQ54YM=
|
||||
modernc.org/fileutil v1.3.8/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
|
||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
||||
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
||||
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
||||
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
||||
modernc.org/libc v1.66.3 h1:cfCbjTUcdsKyyZZfEUKfoHcP3S0Wkvz3jgSzByEWVCQ=
|
||||
modernc.org/libc v1.66.3/go.mod h1:XD9zO8kt59cANKvHPXpx7yS2ELPheAey0vjIuZOhOU8=
|
||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
|
||||
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||
modernc.org/sqlite v1.38.2 h1:Aclu7+tgjgcQVShZqim41Bbw9Cho0y/7WzYptXqkEek=
|
||||
modernc.org/sqlite v1.38.2/go.mod h1:cPTJYSlgg3Sfg046yBShXENNtPrWrDX8bsbAQBzgQ5E=
|
||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package constants
|
||||
|
||||
var VolumeRoot = "/home/nicolas/ironmount/tmp"
|
||||
var VolumeRoot = "/tmp/ironmount"
|
||||
|
||||
26
internal/core/log.go
Normal file
26
internal/core/log.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
stdlog "log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func init() {
|
||||
console := zerolog.ConsoleWriter{
|
||||
Out: os.Stderr,
|
||||
TimeFormat: time.ANSIC,
|
||||
}
|
||||
|
||||
logger := zerolog.New(console).With().Timestamp().Caller().Logger()
|
||||
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
|
||||
log.Logger = logger
|
||||
|
||||
stdlog.SetFlags(0)
|
||||
stdlog.SetOutput(console)
|
||||
}
|
||||
@@ -2,8 +2,8 @@ package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
@@ -59,10 +59,9 @@ func CreateVolume(name, path string) error {
|
||||
func RemoveVolume(name string) error {
|
||||
_, err := DB.Exec("DELETE FROM volumes WHERE name = ?", name)
|
||||
|
||||
log.Printf("Removing volume: %s", name)
|
||||
log.Printf("Error removing volume: %v", err)
|
||||
|
||||
log.Info().Str("volume", name).Msg("Removing volume")
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("volume", name).Msg("Error removing volume")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -2,13 +2,10 @@ package driver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Activate(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received activation request: %s", r.URL.Path)
|
||||
|
||||
resp := map[string]any{
|
||||
"Implements": []string{"VolumeDriver"},
|
||||
}
|
||||
|
||||
@@ -2,25 +2,28 @@ package driver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"ironmount/internal/constants"
|
||||
"ironmount/internal/core"
|
||||
"ironmount/internal/db"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func Create(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received create request: %s", r.URL.Path)
|
||||
|
||||
var req struct {
|
||||
Name string
|
||||
Opts map[string]string `json:"Opts,omitempty"`
|
||||
}
|
||||
_ = json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
volPath := filepath.Join(constants.VolumeRoot, req.Name)
|
||||
cfg := core.LoadConfig()
|
||||
volPath := filepath.Join(cfg.VolumeRoot, req.Name)
|
||||
|
||||
log.Info().Str("path", volPath).Msg("Creating volume directory")
|
||||
if err := os.MkdirAll(volPath, 0755); err != nil {
|
||||
log.Error().Err(err).Str("path", volPath).Msg("Failed to create volume directory")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"Err": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@ package driver
|
||||
import (
|
||||
"encoding/json"
|
||||
"ironmount/internal/db"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/rs/zerolog/hlog"
|
||||
)
|
||||
|
||||
func Get(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received get request: %s", r.URL.Path)
|
||||
|
||||
var req struct {
|
||||
Name string
|
||||
}
|
||||
@@ -18,7 +17,7 @@ func Get(w http.ResponseWriter, r *http.Request) {
|
||||
vol, err := db.GetVolumeByName(req.Name)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Error retrieving volume: %s", err.Error())
|
||||
hlog.FromRequest(r).Error().Err(err).Msg("Error retrieving volume")
|
||||
|
||||
response := map[string]string{
|
||||
"Err": err.Error(),
|
||||
|
||||
@@ -3,16 +3,15 @@ package driver
|
||||
import (
|
||||
"encoding/json"
|
||||
"ironmount/internal/db"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/rs/zerolog/hlog"
|
||||
)
|
||||
|
||||
func List(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received list request: %s", r.URL.Path)
|
||||
|
||||
volumes, err := db.ListVolumes()
|
||||
if err != nil {
|
||||
log.Printf("Error listing volumes: %s", err.Error())
|
||||
hlog.FromRequest(r).Error().Err(err).Msg("Error listing volumes")
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"Volumes": nil,
|
||||
"Err": err.Error(),
|
||||
|
||||
@@ -3,30 +3,34 @@ package driver
|
||||
import (
|
||||
"encoding/json"
|
||||
"ironmount/internal/db"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func Mount(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received mount request: %s", r.URL.Path)
|
||||
|
||||
var req MountRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
if err != nil {
|
||||
hlog.FromRequest(r).Error().Err(err).Msg("Invalid request body")
|
||||
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
vol, err := db.GetVolumeByName(req.Name)
|
||||
if err != nil {
|
||||
log.Printf("Error retrieving volume: %s", err.Error())
|
||||
log.Error().Err(err).Str("volume", req.Name).Msg("Failed to get volume")
|
||||
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
||||
"Err": err.Error(),
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().Str("volume", vol.Name).Str("path", vol.Path).Msg("Mounting volume")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
||||
"Mountpoint": vol.Path,
|
||||
"Err": "",
|
||||
|
||||
@@ -3,18 +3,18 @@ package driver
|
||||
import (
|
||||
"encoding/json"
|
||||
"ironmount/internal/db"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/rs/zerolog/hlog"
|
||||
)
|
||||
|
||||
func Path(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received path request: %s", r.URL.Path)
|
||||
|
||||
var req PathRequest
|
||||
_ = json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
vol, err := db.GetVolumeByName(req.Name)
|
||||
if err != nil {
|
||||
hlog.FromRequest(r).Error().Err(err).Msg("Error retrieving volume")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
||||
"Err": err.Error(),
|
||||
})
|
||||
|
||||
@@ -3,20 +3,20 @@ package driver
|
||||
import (
|
||||
"encoding/json"
|
||||
"ironmount/internal/db"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func Remove(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received remove request: %s", r.URL.Path)
|
||||
|
||||
var req RemoveRequest
|
||||
_ = json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
vol, err := db.GetVolumeByName(req.Name)
|
||||
if err != nil {
|
||||
log.Printf("Error retrieving volume: %s", err.Error())
|
||||
hlog.FromRequest(r).Error().Err(err).Msg("Error retrieving volume")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
||||
"Err": err.Error(),
|
||||
})
|
||||
@@ -24,6 +24,8 @@ func Remove(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
db.RemoveVolume(vol.Name)
|
||||
|
||||
log.Info().Str("path", vol.Path).Msg("Removing volume directory")
|
||||
os.RemoveAll(vol.Path)
|
||||
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"Err": ""})
|
||||
|
||||
@@ -2,12 +2,9 @@ package driver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Unmount(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received unmount request: %s", r.URL.Path)
|
||||
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"Err": ""})
|
||||
}
|
||||
|
||||
53
main.go
53
main.go
@@ -3,10 +3,14 @@ package main
|
||||
import (
|
||||
"ironmount/internal/db"
|
||||
"ironmount/internal/driver"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/justinas/alice"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const volumeRoot = "/tmp/ironmount"
|
||||
@@ -22,42 +26,53 @@ func main() {
|
||||
db.Init()
|
||||
|
||||
if err := os.MkdirAll("/run/docker/plugins", 0755); err != nil {
|
||||
log.Fatalf("Failed to create plugin directory: %v", err)
|
||||
log.Fatal().Err(err).Msg("Failed to create plugin directory")
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(volumeRoot, 0755); err != nil {
|
||||
log.Fatalf("Failed to create volume root: %v", err)
|
||||
log.Fatal().Err(err).Msg("Failed to create volume root")
|
||||
}
|
||||
|
||||
if err := os.MkdirAll("/run/docker/plugins", 0755); err != nil {
|
||||
log.Fatalf("Failed to create plugin directory: %v", err)
|
||||
log.Fatal().Err(err).Msg("Failed to create plugin directory")
|
||||
}
|
||||
|
||||
socketPath := "/run/docker/plugins/ironmount.sock"
|
||||
if err := os.RemoveAll(socketPath); err != nil {
|
||||
log.Fatalf("Failed to remove existing socket: %v", err)
|
||||
log.Fatal().Err(err).Msg("Failed to remove existing socket")
|
||||
}
|
||||
|
||||
http.HandleFunc("/Plugin.Activate", driver.Activate)
|
||||
http.HandleFunc("/VolumeDriver.Create", driver.Create)
|
||||
http.HandleFunc("/VolumeDriver.Remove", driver.Remove)
|
||||
http.HandleFunc("/VolumeDriver.Mount", driver.Mount)
|
||||
http.HandleFunc("/VolumeDriver.Unmount", driver.Unmount)
|
||||
http.HandleFunc("/VolumeDriver.Path", driver.Path)
|
||||
http.HandleFunc("/VolumeDriver.Get", driver.Get)
|
||||
http.HandleFunc("/VolumeDriver.List", driver.List)
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/Plugin.Activate", driver.Activate)
|
||||
mux.HandleFunc("/VolumeDriver.Create", driver.Create)
|
||||
mux.HandleFunc("/VolumeDriver.Remove", driver.Remove)
|
||||
mux.HandleFunc("/VolumeDriver.Mount", driver.Mount)
|
||||
mux.HandleFunc("/VolumeDriver.Unmount", driver.Unmount)
|
||||
mux.HandleFunc("/VolumeDriver.Path", driver.Path)
|
||||
mux.HandleFunc("/VolumeDriver.Get", driver.Get)
|
||||
mux.HandleFunc("/VolumeDriver.List", driver.List)
|
||||
|
||||
// Catch all other paths to return an error
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received unknown request: %s", r.URL.Path)
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Not Found", http.StatusNotFound)
|
||||
})
|
||||
|
||||
listener, err := net.Listen("unix", socketPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to listen on socket: %v", err)
|
||||
log.Fatal().Err(err).Msg("Failed to listen on socket")
|
||||
}
|
||||
|
||||
log.Printf("Irounmount plugin started, listening on %s", socketPath)
|
||||
log.Fatal(http.Serve(listener, nil))
|
||||
chain := alice.New()
|
||||
chain = chain.Append(hlog.NewHandler(log.Logger))
|
||||
chain = chain.Append(hlog.AccessHandler(func(r *http.Request, status, size int, duration time.Duration) {
|
||||
hlog.FromRequest(r).Info().
|
||||
Str("method", r.Method).
|
||||
Str("url", r.URL.Path).
|
||||
Int("status", status).
|
||||
Msg("")
|
||||
}))
|
||||
|
||||
log.Info().Str("socket", socketPath).Msg("Irounmount plugin started, listening on")
|
||||
if err := http.Serve(listener, chain.Then(mux)); err != nil {
|
||||
log.Fatal().Err(err).Msg("Server stopped")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user