16
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
* */
18
18
import "dotenv/config" ;
19
+ import fs from "fs" ;
19
20
import http from "http" ;
20
21
21
22
import { AbsURL , OpenAPI } from "acts-util-core" ;
22
23
import { Factory , GlobalInjector , HTTP } from "acts-util-node" ;
23
24
import { APIRegistry } from "acts-util-apilib" ;
24
25
import { DBConnectionsManager } from "./data-access/DBConnectionsManager" ;
25
- import { CONFIG_OIDP_ENDPOINT , CONFIG_ORIGIN , CONFIG_PORT , CONFIG_UPLOADDIR } from "./env" ;
26
+ import { CONFIG_OIDP_ENDPOINT , CONFIG_ORIGIN , CONFIG_PORT , CONFIG_ROOTDIR , CONFIG_UPLOADDIR } from "./env" ;
26
27
import { FtpSrv , GeneralError } from "ftp-srv" ;
27
28
import { FTPFileSystem } from "./FTPFileSystem" ;
28
29
import { StorageBackendsManager } from "./services/StorageBackendsManager" ;
@@ -35,6 +36,8 @@ import { AccessCounterService } from "./services/AccessCounterService";
35
36
import { StorageBlocksManager } from "./services/StorageBlocksManager" ;
36
37
import { FileUploadService } from "./services/FileUploadService" ;
37
38
39
+ const crashDetectionPath = CONFIG_ROOTDIR + "/crash_check" ;
40
+
38
41
async function DownloadPublicKey ( )
39
42
{
40
43
const sender = new HTTP . RequestSender ( ) ;
@@ -129,6 +132,7 @@ async function BootstrapServer()
129
132
console . log ( "Shutting server down..." ) ;
130
133
GlobalInjector . Resolve ( DBConnectionsManager ) . Close ( ) ;
131
134
GlobalInjector . Resolve ( MessagingService ) . Close ( ) ;
135
+ fs . unlinkSync ( crashDetectionPath ) ;
132
136
server . close ( ) ;
133
137
} ) ;
134
138
}
@@ -160,5 +164,24 @@ function BootstrapFTPServer()
160
164
} ) ;
161
165
}
162
166
163
- BootstrapServer ( ) ;
164
- BootstrapFTPServer ( ) ;
167
+ function BootstrapService ( )
168
+ {
169
+ if ( fs . existsSync ( crashDetectionPath ) )
170
+ {
171
+ console . log ( "Service did crash :S" ) ;
172
+ process . exit ( 1 ) ;
173
+ return ;
174
+ }
175
+ process . on ( "uncaughtException" , ( error , origin ) => {
176
+ console . log ( "Unhandled exception: " , error , origin ) ;
177
+ } ) ;
178
+ process . on ( "unhandledRejection" , ( reason , promise ) => {
179
+ console . log ( "Unhandled rejection: " , reason , promise ) ;
180
+ } ) ;
181
+ fs . writeFileSync ( crashDetectionPath , "" ) ;
182
+
183
+ BootstrapServer ( ) ;
184
+ BootstrapFTPServer ( ) ;
185
+ }
186
+
187
+ BootstrapService ( ) ;
0 commit comments