Add cleanup script to fix any problems arising from restarting the server mid-stream.

This may cause further problems if the user manages to reconnect before the cleanup script has finished, but the server *shouldn't* start listening until after the script is done.
Increment version I guess, I don't really know how versioning works.
merge-requests/1/head
knotteye 5 years ago
parent 8cc8083361
commit 61bf54de95
  1. 10
      package-lock.json
  2. 3
      package.json
  3. 23
      src/cleanup.ts
  4. 6
      src/controller.ts

10
package-lock.json generated

@ -1,6 +1,6 @@
{
"name": "satyr",
"version": "0.2.0",
"version": "0.3.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -2370,6 +2370,14 @@
"readable-stream": "^2.0.2"
}
},
"recursive-readdir": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/recursive-readdir/-/recursive-readdir-2.2.2.tgz",
"integrity": "sha512-nRCcW9Sj7NuZwa2XvH9co8NPeXUBhZP7CRKJtU+cS6PW9FpCIFoI5ib0NT1ZrbNuPoRy0ylyCaUL8Gih4LSyFg==",
"requires": {
"minimatch": "3.0.4"
}
},
"regex-not": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz",

@ -1,6 +1,6 @@
{
"name": "satyr",
"version": "0.3.0",
"version": "0.3.1",
"description": "A livestreaming server.",
"license": "AGPL-3.0",
"author": "knotteye",
@ -24,6 +24,7 @@
"mysql": "^2.17.1",
"node-media-server": ">=2.1.3 <3.0.0",
"nunjucks": "^3.2.0",
"recursive-readdir": "^2.2.2",
"socket.io": "^2.3.0",
"toml": "^3.0.0"
},

@ -0,0 +1,23 @@
import * as db from "./database";
import * as read from "recursive-readdir";
import * as fs from "fs";
async function init(siteDir: string) {
//If satyr is restarted in the middle of a stream
//it causes problems
//Live flags in the database stay live
await db.query('update user_meta set live=false');
//and stray m3u8 files will play the last
//few seconds of a stream back
try {
var files = await read(siteDir+'/live', ['!*.m3u8']);
}
catch (error) {}
if(files === undefined || files.length == 0) return;
for(let i=0;i<files.length;i++){
fs.unlinkSync(files[i]);
}
return;
}
export { init };

@ -2,9 +2,10 @@ import * as mediaserver from "./server";
import * as db from "./database";
import * as api from "./api";
import * as http from "./http";
import * as cleanup from "./cleanup"
import * as config from "config";
function run(): void{
async function run() {
const dbcfg: object = config.database;
const bcryptcfg: object = config.bcrypt;
const satyr: object = {
@ -52,9 +53,10 @@ function run(): void{
}
};
db.init(dbcfg, bcryptcfg);
await cleanup.init(config.server.http.directory);
api.init(satyr);
http.init(satyr, config.server.http.port);
db.init(dbcfg, bcryptcfg);
mediaserver.init(nms, satyr);
}
run();