0

I have packaged a Debian file of our software. Now there is a .sh script that needs to be started to run the program/software. This .sh script actually runs a Django server and few more services.

To actually start this application, we need to run the .desktop file in the menu. This .desktop file in the menu is associated with the .sh script mentioned above. This prompts the terminal and asks for the password. Once the password is given, this will start the services and the terminal stays active.

To close this service completely, we need to kill the process by finding the PID of the process and killing it from the terminal. But now I want to kill this process when I close the terminal.

How can I do that?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Tejas Shah
  • 55
  • 9
  • Possible duplicate of [Best way to kill all child processes](http://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes) – CPHPython Jan 05 '17 at 15:02
  • are you starting your servers from a desktop icon? i'd rather checkout `systemd.unit` for one (of several) proper way(s) to start a daemon. – umläute Jan 05 '17 at 15:48

2 Answers2

0

If you are trying to create a service (some program that runs in the background), you should create use your system's mechanism for this. The traditional one, would be a scrip in /etc/init.d/, a more modern approach is to use systemd.

E.g. a file /etc/systemd/system/myservice.system

[Unit]
Description=My Service

[Service]
Type=simple

# you could run the service as a special user
#User=specialuser
WorkingDirectory=/var/lib/myservice/
# execute this before starting the actual script
#ExecStartPre=/usr/lib/myservice/bin/prestart.sh
ExecStart=/usr/bin/myservice
Restart=on-failure

[Install]
WantedBy=multi-user.target

You can then start/stop the service (as root) using:

 systemctl start myservice

resp.

 systemctl stop myservice

You can have dependency chains of services, so starting myservice will automatically start myhelper1 and myhelper2.

Checkout the manpage systemd.unit.5

umläute
  • 28,885
  • 9
  • 68
  • 122
0

When the controlling terminal is closed, the foreground process group should receive a SIGHUP signal. If your target process is already expected to be in the foreground, then it may be that it is catching or ignoring SIGHUP (the default behavior for a process receiving that signal is to terminate).

the paul
  • 8,972
  • 1
  • 36
  • 53
  • @ the paul thanks for answering, i had actually not given any path to my deb installation package so all my main software directory and files were in the root folder and my application start script was also in root so is it like as the program/script is associated with root it is ignoring the sighup? Because today i repackaged my software into a deb installer and i gave the installation path to be /usr/share, after this now when i installed the deb again all my main software file are stored in /usr/share now when i am closing the terminal the process are also automatically getting killed – Tejas Shah Jan 08 '17 at 00:00
  • No. The directory in which the binary is found has no effect on signal handling. – the paul Jan 08 '17 at 00:02
  • Paul but now the new problem arrised that is when i am trying to install the deb with other non root user, when i am clicking in the deb then the software installer is started then after some time it prompt for the administrator password with a warning that "to install this software you will need administrative access" but even after properly supplying the password the software installer closes automatically without installing the software can you help me resolving with this?? – Tejas Shah Jan 08 '17 at 00:10
  • 1
    You should start a new question if you need to ask something else. – the paul Jan 16 '17 at 16:40