@@ -19,7 +19,6 @@ import (
19
19
"github.com/gorilla/mux"
20
20
"github.com/gorilla/websocket"
21
21
log "github.com/sirupsen/logrus"
22
- "gopkg.in/ini.v1"
23
22
)
24
23
25
24
var configDir string
@@ -46,36 +45,12 @@ func init() {
46
45
}
47
46
48
47
func loadNotifConfig () {
49
- notifyConfPath := filepath .Join (configDir , "seafile.conf" )
50
-
51
- opts := ini.LoadOptions {}
52
- opts .SpaceBeforeInlineComment = true
53
- config , err := ini .LoadSources (opts , notifyConfPath )
54
- if err != nil {
55
- log .Fatalf ("Failed to load notification.conf: %v" , err )
56
- }
57
-
58
- section , err := config .GetSection ("notification" )
59
- if err != nil {
60
- log .Fatal ("No notification section in seafile.conf." )
61
- }
62
-
63
48
host = "0.0.0.0"
64
49
port = 8083
65
- logLevel := "info"
66
- if key , err := section .GetKey ("host" ); err == nil {
67
- host = key .String ()
68
- }
69
-
70
- if key , err := section .GetKey ("port" ); err == nil {
71
- n , err := key .Uint ()
72
- if err == nil {
73
- port = uint32 (n )
74
- }
75
- }
76
50
77
- if key , err := section .GetKey ("log_level" ); err == nil {
78
- logLevel = key .String ()
51
+ logLevel := os .Getenv ("NOTIFICATION_SERVER_LOG_LEVEL" )
52
+ if logLevel == "" {
53
+ logLevel = "info"
79
54
}
80
55
81
56
level , err := log .ParseLevel (logLevel )
@@ -90,11 +65,7 @@ func loadNotifConfig() {
90
65
func loadCcnetDB () {
91
66
option , err := loadDBOptionFromEnv ()
92
67
if err != nil {
93
- log .Infof ("Failed to load database from env: %v" , err )
94
- option , err = loadDBOptionFromFile ()
95
- if err != nil {
96
- log .Fatalf ("Failed to load database: %v" , err )
97
- }
68
+ log .Fatalf ("Failed to load database from env: %v" , err )
98
69
}
99
70
100
71
var dsn string
@@ -132,7 +103,7 @@ func loadDBOptionFromEnv() (*DBOption, error) {
132
103
return nil , fmt .Errorf ("failed to read SEAFILE_MYSQL_DB_USER" )
133
104
}
134
105
password := os .Getenv ("SEAFILE_MYSQL_DB_PASSWORD" )
135
- if user == "" {
106
+ if password == "" {
136
107
return nil , fmt .Errorf ("failed to read SEAFILE_MYSQL_DB_PASSWORD" )
137
108
}
138
109
host := os .Getenv ("SEAFILE_MYSQL_DB_HOST" )
@@ -165,80 +136,6 @@ func loadDBOptionFromEnv() (*DBOption, error) {
165
136
return option , nil
166
137
}
167
138
168
- func loadDBOptionFromFile () (* DBOption , error ) {
169
- confPath := filepath .Join (configDir , "seafile.conf" )
170
- config , err := ini .Load (confPath )
171
- if err != nil {
172
- return nil , fmt .Errorf ("failed to load seafile.conf: %v" , err )
173
- }
174
-
175
- section , err := config .GetSection ("database" )
176
- if err != nil {
177
- return nil , fmt .Errorf ("no database section in seafile.conf" )
178
- }
179
-
180
- var dbEngine string = "mysql"
181
- key , err := section .GetKey ("type" )
182
- if err == nil {
183
- dbEngine = key .String ()
184
- }
185
-
186
- if ! strings .EqualFold (dbEngine , "mysql" ) {
187
- return nil , fmt .Errorf ("unsupported database %s" , dbEngine )
188
- }
189
-
190
- unixSocket := ""
191
- if key , err = section .GetKey ("unix_socket" ); err == nil {
192
- unixSocket = key .String ()
193
- }
194
-
195
- host := ""
196
- if key , err = section .GetKey ("host" ); err == nil {
197
- host = key .String ()
198
- } else if unixSocket == "" {
199
- return nil , fmt .Errorf ("no database host in seafile.conf" )
200
- }
201
- // user is required.
202
- if key , err = section .GetKey ("user" ); err != nil {
203
- return nil , fmt .Errorf ("no database user in seafile.conf" )
204
- }
205
- user := key .String ()
206
- password := ""
207
- if key , err = section .GetKey ("password" ); err == nil {
208
- password = key .String ()
209
- } else if unixSocket == "" {
210
- return nil , fmt .Errorf ("no database password in seafile.conf" )
211
- }
212
- if key , err = section .GetKey ("db_name" ); err != nil {
213
- return nil , fmt .Errorf ("no database db_name in seafile.conf" )
214
- }
215
- seafileDbName := key .String ()
216
- if key , err = section .GetKey ("ccnet_db_name" ); err != nil {
217
- return nil , fmt .Errorf ("no database ccnet_db_name in seafile.conf" )
218
- }
219
- ccnetDbName := key .String ()
220
- port := 3306
221
- if key , err = section .GetKey ("port" ); err == nil {
222
- port , _ = key .Int ()
223
- }
224
- useTLS := false
225
- if key , err = section .GetKey ("USE_SSL" ); err == nil {
226
- useTLS , _ = key .Bool ()
227
- }
228
-
229
- option := new (DBOption )
230
- option .User = user
231
- option .Password = password
232
- option .Host = host
233
- option .Port = port
234
- option .CcnetDbName = ccnetDbName
235
- option .SeafileDbName = seafileDbName
236
- option .UnixSocket = unixSocket
237
- option .UseTLS = useTLS
238
-
239
- return option , nil
240
- }
241
-
242
139
func main () {
243
140
flag .Parse ()
244
141
0 commit comments