@@ -106,12 +106,7 @@ async function start () {
106
106
107
107
app . post ( '/close' , async ( req , res ) => {
108
108
try {
109
- await unmountAll ( hypermount , db )
110
- console . log ( 'unmounted them all' )
111
- await store . close ( )
112
- await db . close ( )
113
- server . close ( )
114
-
109
+ await cleanup ( )
115
110
res . sendStatus ( 200 )
116
111
} catch ( err ) {
117
112
console . error ( 'Close error:' , err )
@@ -126,7 +121,17 @@ async function start () {
126
121
await store . ready ( )
127
122
await refreshMounts ( hypermount , db )
128
123
124
+ process . once ( 'SIGINT' , cleanup )
125
+ process . once ( 'SIGTERM' , cleanup )
126
+
129
127
var server = app . listen ( argv . port || 3005 )
128
+
129
+ async function cleanup ( ) {
130
+ await unmountAll ( hypermount , db )
131
+ await store . close ( )
132
+ await db . close ( )
133
+ server . close ( )
134
+ }
130
135
}
131
136
132
137
async function mount ( hypermount , db , key , mnt , opts ) {
@@ -180,7 +185,6 @@ function refreshMounts (hypermount, db) {
180
185
db . createReadStream ( ) ,
181
186
through . obj ( ( { key, value : record } , enc , cb ) => {
182
187
if ( record . status === Status . UNMOUNTED ) {
183
- console . log ( `Refreshing mount for ${ JSON . stringify ( record ) } ` )
184
188
const mountPromise = mount ( hypermount , db , record . key , key , record )
185
189
mountPromise . then ( ( ) => cb ( null ) )
186
190
mountPromise . catch ( cb )
0 commit comments