LINUX : Restart Gui app from a ssh console - linux

I've a graphical program who has launched inside of the Front-End session.
I want to restart this application from putty, I can stop it by kill but I'm not be able to start application inside of the Front-End session.
When I Call application I get this error : cannot connect to X server

This may be way too late, but you can do it with these steps.
xhost +localhost
export DISPLAY=:0
restart_your_app_here
xhost command ensures your X server will take connections from the localhost.
export tells the X server where to send the X traffic (which is its own localhost).
Third command just restarts your app, you may want to do this in a tmux or screen so that the session doesn't get killed when you log out or get disconnected.

Related

Start node app through ssh, stays running?

I have a raspberry PI on which I run a node server. To start and control the terminal on which the server runs I use desktop remote to remote control the raspberry. Now this method is really slow so I was wondering, since I only need a command line anyway if I couldn't just connect to my raspberry pi using ssh for example.
My question now, would be if I do so, can I navigate to my node folder, run my node file and then close the ssh connection? Will my Node server keep running and if so how would I access the terminal with the node session after closing the connection?
The easiest way to do this is something like:
nohup node myapp.js &
This will make the app run in the background, and nohup prevents it from stopping when the connection closes.
This is a cheap and quick way to do this. A more appropriate way might be one of the following:
Using something like docker to manage running applications.
Using something like supervisord to do the same thing.
Writing scripts for initd and turn it into a real 'service'.
Changing the node application to fork & deamonize itself.

run an app and switch to it via ssh?

I'm currently running a python script as a systemd service. Is there any way to "switch" into the service and take control of the script? The script has a menu but runs calculations in the background in another thread. Most likely not, so is there a way to run a python script 24/7, start on boot, restart on crash etc (just like systemd service) but be able to take control of it after I connect to the server via SSH, so I can manipulate the app?
One solution you could try would be to edit the systemd configuration to launch the process in screen or tmux, then attach that when logging in via SSH.
For instance, in the systemd unit, you might have:
[Service]
Type=single
ExecStart=tmux new "command"
Using Type=single will treat the tmux command as the main process, which would be killed if you stop it with systemctl stop systemprocess
The ExecStart=tmux new "command" creates a new tmux session with the command inside of it.
You can then attach to it using tmux attach as the same user the systemd unit is running as (I believe this is root by default).

Geddy CLI closes on SSH drop

In a remote CentOS VM Geddy application with MonogoDB wrapper is deployed. The application starts and listen to port 80 when below command is executed.
geddy -e production &
The problem in this CLI command is when the SSH connection to VM was disconnected the process automatically gets closed. To make application working SSH needs to be opened always which is not possible. Is there any alternative method to keep it running as background service.
This happens because processes that are merely backgrounded will be sent a SIGHUP signal when their controlling terminal (the SSH connection) is closed.
The traditional method of preventing this is using the nohup utility:
nohup geddy -e production &
Alternatively, you can use terminal multiplexers like screen or tmux to create persistent terminal sessions (ones that remain active when you log out, and that can be reattached when you log in again at a later time).

Launching multiple GUI programs from crontab

I want to launch multiple GUI programs from crontab. I have tried the following, but it did not work:
export DISPLAY=:0.0 && task1
export DISPLAY=:1.0 && task2
When I execute above crontab commands, I am getting error as:
**No more handles [gtk_init_check() failed]**
1) You need to allow clients to connect from any host using xhost + <clientmachineName>
So it will look like:
hostmachine$ xhost + <clientmachineName>
2) Then connect to the client machine either directly or from any third machine where the VNC is enabled.
If you are using the third machine & not the client machine itself, then you need to enable x11 forwarding, by executing ssh -X <username#clientmachine>
3) After that you can open the gui application of the host machine, from the client terminal running on the client machine or the client terminal running on the vnc session of the third machine, for which export DISPLAY=<thirdmachine>:<sessionid no> is required.

nodejs server - mac terminal crash every one hour

I got a live server running nodejs chat app. I connect to server using terminal on mac. I start the server by typing server.js.
the problem is, my terminal always hung after one hour running, and there are no error outputs. when it hangs, I press ctrl+c I got the message [process completed].
note: My terminal runs node apps locally without any problems.
And my current chat app run well when I initiate it with WinSCP in windows platform.
Try launching your node process on the remote server using a tool like nohup.
bash$ nohup /path/to/node server.js > out.txt 2> err.txt &
[1] 53032
# Now you can logout of the remote server without
# killing the "node" process and chat server.
[Edit]
Note that the number printed by "nohup" (e.g. 53032) is the id of detached process, so if you need to terminate it you can do something like "kill -9 53032". If you forgot to record that number then you'll have to find it by using a program such as "ps"; for example, you can run "ps auxwww | grep node" (the flags will vary depending on your system) and you'll see output similar to this:
maerics 81694 0.6 0.5 2543604 21216 s000 S+ 10:34AM 0:09.45 /Users/maerics/opt/node/node server.js
In this example, on my system, the number in the second column is the process id.

Resources