You are not logged in.

#1 2016-09-17 02:12:39

Maniaxx
Member
Registered: 2014-05-14
Posts: 738

[SOLVED] NOHUP terminates after terminal closed

Hallo,
i want to start a shell script from Cinnamon starter (desktop icon). The command in the starter is: sudo /home/user/bin/myscript.sh. The script should manually start a vnc server on-demand (beside other things not relevant here. Sudo is needed for other stuff). VNC works if started manually.

This is the content of the script:

#!/bin/sh
nohup x0vncserver -display :0 -passwordfile /home/user/.vnc/passwd &
sleep 5

The vnc server (process) only lives as long as the terminal (5 seconds). The 'nohup.out' just shows 'Terminated'.

Why is this happening? How can i keep the process running after the terminal closes?

Last edited by Maniaxx (2016-09-17 19:52:39)


sys2064

Offline

#2 2016-09-17 02:21:15

headkase
Member
Registered: 2011-12-06
Posts: 1,976

Re: [SOLVED] NOHUP terminates after terminal closed

Have you just tried "exec .." ?  and then don't background the process (&) but instead no nothing.  The process should live on as long as your user is logged in.

Offline

#3 2016-09-17 02:29:29

Maniaxx
Member
Registered: 2014-05-14
Posts: 738

Re: [SOLVED] NOHUP terminates after terminal closed

Then it hangs there. Appending a '&' gives same '5 seconds' result.


sys2064

Offline

#4 2016-09-17 02:47:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: [SOLVED] NOHUP terminates after terminal closed

Maniaxx wrote:

The vnc server (process) only lives as long as the terminal (5 seconds).

Terminal?  What terminal?  Do you just mean the parent process?

You should probably use setsid not nohup.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2016-09-17 03:26:20

Maniaxx
Member
Registered: 2014-05-14
Posts: 738

Re: [SOLVED] NOHUP terminates after terminal closed

Sorry, i meant the shell window that opens once you double click the icon. Not a terminal indeed.
And yes, setsid works indeed. Never heard of it but i learned something today. smile

Thanks!

Last edited by Maniaxx (2016-09-17 03:26:41)


sys2064

Offline

#6 2016-09-17 13:01:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: [SOLVED] NOHUP terminates after terminal closed

If a shell window opens, then it is a terminal emulator.  But there really shouldn't be - you should be able to set it to not open the terminal window.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2016-09-17 17:04:00

Maniaxx
Member
Registered: 2014-05-14
Posts: 738

Re: [SOLVED] NOHUP terminates after terminal closed

Shell window is intended. It gives me feedback about proper execution. I spawn VNC, OpenVPN, NFS services, mount NTFS drives and bind mount some folders to my NFS exports. The script will close immediately due to 'set -e' if anything goes wrong. I don't want to have this stuff permanently running.


sys2064

Offline

Board footer

Powered by FluxBB