0

I've got a cli application written in nodejs using vorpal , live in a freebsd (v9.3), I need to know is there any way to prevent the user from exiting this app or not! I want it like when the application has started , it will never exit until reboot or shutting down the system. this is very critical and I mean it no way to exit the application at any cost . Is it possible at all ?

Edit: This is what i want: when my program start ,user can not exit the program except my own exit command, So i want to somehow prevent CTRL-Z,CTRL-C Or any other things like them. I can handle the SIGINT and errors but my problem is with "CTRL-Z" which fires a SIGSTOP signal and node cant listen to it . how can I disable this CTRL-z and others at all ? or is there any other solution maybe in my code or even modifying the bsd?

Omid Navy
  • 272
  • 2
  • 12
  • 1
    Have you taken a look at these modules? https://github.com/Unitech/pm2 https://www.npmjs.com/package/forever – Khauri Jul 09 '17 at 12:39
  • give a try to https://immortal.run/freebsd/ works in FreeBSD out of the box – nbari Jul 10 '17 at 14:04

2 Answers2

1

There is a few ways to accomplish this, depends on what you're asking:

1) using an external tool to restart the process on exit or crash (like Khauri McClain said in a comment). Some of them are (my favourite is pm2):

2) You can prevent Node.js from exiting on error: Make node.js not exit on error, but please don't do it, this answer explains why: https://stackoverflow.com/a/13049037/1206421. Also you can apparently ignore Control-C keypresses with this module: https://www.npmjs.com/package/ctrl-c (I didn't look into it), but this seems like a bad idea too.

Anyway, if the process you are using will be killed by system or another user (for example, with kill -9), there's nothing you can do about it except for using some auto-restart services, like I described above. I suggest you to start using them.

serge1peshcoff
  • 4,342
  • 11
  • 45
  • 76
  • I want no terminal access , so there is no kill -9 or etc , just when the user logged in , my program start and user cant access any other thing . I can handle the SIGINT and errors but my problem is with "CTRL-Z" which fires a SIGSTOP signal and node cant listen to it . how can i disable this ctrl-z at all ? maybe in my code or even modifying the bsd? – Omid Navy Jul 11 '17 at 08:02
1

I found my answer in freebsd forums , here i want to share with you for those with same purpose.

As mentioned in that forum, I needed to wrap my program inside a C program which can detect and ignore signals . So this is the way:

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
        /* Ignore signals from keyboard */
        signal(SIGINT, SIG_IGN);
        signal(SIGTSTP, SIG_IGN);
        signal(SIGQUIT, SIG_IGN);

    system("node path/to/your/program");
    /* Whatever needs to be done if this point is reached. */
    return (0);
}
Omid Navy
  • 272
  • 2
  • 12