1 import Config
from './config';
2 import * as Switches
from './switches';
3 import { eventlog
} from './logger';
4 require('source-map-support').install();
6 const LOGGER
= require('@calzoneman/jsli')('main');
9 Config
.load('config.yaml');
12 "Failed to load configuration: %s",
18 const sv
= require('./server').init();
20 if (!Config
.get('debug')) {
21 process
.on('uncaughtException', error
=> {
22 LOGGER
.fatal('Uncaught exception: %s', error
.stack
);
25 process
.on('SIGINT', () => {
26 LOGGER
.info('Caught SIGINT; shutting down');
31 // TODO: this can probably just be part of servsock.js
32 // servsock should also be refactored to send replies instead of
33 // relying solely on tailing logs
34 function handleLine(line
) {
35 if (line
=== '/reload') {
36 LOGGER
.info('Reloading config');
38 Config
.load('config.yaml');
41 "Failed to load configuration: %s",
45 require('./web/pug').clearCache();
46 } else if (line
.indexOf('/switch') === 0) {
47 const args
= line
.split(' ');
49 if (args
.length
=== 1) {
50 LOGGER
.info('Switch ' + args
[0] + ' is ' +
51 (Switches
.isActive(args
[0]) ? 'ON' : 'OFF'));
52 } else if (args
.length
=== 2) {
53 Switches
.setActive(args
[0], args
[1].toLowerCase() === 'on' ? true : false);
54 LOGGER
.info('Switch ' + args
[0] + ' is now ' +
55 (Switches
.isActive(args
[0]) ? 'ON' : 'OFF'));
57 } else if (line
.indexOf('/reload-partitions') === 0) {
58 sv
.reloadPartitionMap();
59 } else if (line
.indexOf('/save') === 0) {
61 } else if (line
.indexOf('/unloadchan') === 0) {
62 const args
= line
.split(/\s+/); args
.shift();
64 const name
= args
.shift();
65 const chan
= sv
.getChannel(name
);
66 const users
= Array
.prototype.slice
.call(chan
.users
);
68 users
.forEach(function (u
) {
69 u
.kick('Channel shutting down');
71 eventlog
.log('[acp] ' + 'SYSTEM' + ' forced unload of ' + name
);
73 } else if (line
.indexOf('/reloadcert') === 0) {
74 sv
.reloadCertificateData();
78 // Go Go Gadget Service Socket
79 if (Config
.get('service-socket.enabled')) {
80 LOGGER
.info('Opening service socket');
81 const ServiceSocket
= require('./servsock');
82 const sock
= new ServiceSocket();
89 'Error in UNIX socket command handler: %s',
94 Config
.get('service-socket.socket')
99 process
.stdin
.on('data', function (data
) {
101 if (stdinbuf
.indexOf('\n') !== -1) {
102 let line
= stdinbuf
.substring(0, stdinbuf
.indexOf('\n'));
103 stdinbuf
= stdinbuf
.substring(stdinbuf
.indexOf('\n') + 1);
107 LOGGER
.error('Command line input handler failed: %s', error
.stack
);
112 // Hi I'm Mr POSIX! Look at me!
113 process
.on('SIGUSR2', () => {
114 sv
.reloadCertificateData();
118 process
.on('unhandledRejection', function (reason
, _promise
) {
119 LOGGER
.error('Unhandled rejection: %s', reason
.stack
);