`Is it possible to intercept the call of the program termination command in the terminal?
E
E
Egor Mikheev2019-09-02 15:37:02
linux
Egor Mikheev, 2019-09-02 15:37:02

Is it possible to intercept the call of the program termination command in the terminal?

There is a script that launches several programs and ultimately remains access through pressing the ctrl + c combination only for the last launched program.
for example `cd hapi && npm run hapi & cd ../ & node scripts/start.js`
starts the frontend server and the backend server.
- When the program is terminated, only the frontend server
is terminated accordingly - is it possible to somehow intercept pressing ctrl + c or ctrl + z and, by calling the appropriate commands, terminate the work and the back end of the program?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Barbolin, 2019-09-02
@ogregor

Tin. Change to systemd.
vim /etc/systemd/system/backend.service
[Service]
ExecStart=/usr/bin/node /opt/backend/server.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=backend
User=root
Group=root
WorkingDirectory= /opt/backend
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start backend.service

R
Radjah, 2019-09-02
@Radjah

Write two units for systemd and not do any costing, for example.
You can even run it through systemd-run if you try it once.

A
Adamos, 2019-09-02
@Adamos

man-kill

S
sash999, 2019-09-02
@sash999

Theoretically, it is possible through the interception of signals using trap. But it is more correct, as already said, to do everything with systemd.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question