I'm developing a cross platform CLI service manager like PM2 using node-windows and node-linux. It's fine using node-windows, it's working perfectly, but with node-linux 'm getting some strange errors.
Just to make it clear, I need to run a web-server that is an executable (that I generated with PKG), so I was thinking that was the problem, but using a simple hello.js file didn't resolve the error below:
Note: I've tested in Kali Linux and Ubuntu :/
Passei 0
Using default mode: systemd
Passei 1
Installing service on /etc/systemd/system/premiernutri.service
/home/kali/Desktop/Projects/cli/node_modules/mu2/lib/mu.js:118
throw new Error('template_not_in_cache'); //errors.templateNotInCache(filename)));
^
Error: template_not_in_cache
at Object.mu.render (/home/kali/Desktop/Projects/cli/node_modules/mu2/lib/mu.js:118:11)
at null.<anonymous> (/home/kali/Desktop/Projects/cli/node_modules/node-linux/lib/systemd.js:158:29)
at null.<anonymous> (/home/kali/Desktop/Projects/cli/node_modules/mu2/lib/mu.js:43:14)
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
My Install.ts CLI code
// eslint-disable-next-line import/named
import { Service as LinuxService } from 'node-linux';
import path from 'path';
import { env } from '@config/env';
import Command from '@shared/decorators/Command';
async function handle() {
if (process.platform === 'win32') {
const { Service: WindowsService } = await import('node-windows');
const appName = env.EXECUTABLE_NAME || 'app.exe';
// Create a new service object
const svc = new WindowsService({
name: env.SERVICE_NAME,
description: env.SERVICE_DESCRIPTION,
script: '',
execPath: path.join(__dirname, '..', '..', 'app', appName),
maxRetries: 3,
wait: 3,
});
svc.workingdirectory = path.join(__dirname, '..', '..', 'app');
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install', () => {
svc.start();
});
svc.install();
} else {
const appName = env.EXECUTABLE_NAME || 'app';
console.log('Passei 0');
const svc = new LinuxService({
name: env.SERVICE_NAME,
description: env.SERVICE_DESCRIPTION,
script: path.join(__dirname, '..', '..', 'app', appName),
maxRetries: 3,
wait: 3,
});
console.log('Passei 1');
// svc.workingDirectory = path.join(__dirname, '..', '..', 'app');
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install', () => {
svc.start();
});
svc.install();
}
}
@Command({
name: 'install',
handle,
})
export default class InstallCommand {}