linux running program to be shown again when console closed unfortunately - linux

I am running a automatic installation in linux by running some command in cli
root#server$ sudo install some-devl
if unfortunatly even before the installation finishes the console become closed (putty to assume )
we can check if that is running or not by relaunching and running putty again with login
ps -eaf | grep install*
but is the anyway to continute to show in install output on screen again ?

One way to make your session resilient to disconnections is to use the screen command.
Another thing to try is to prevent the disconnects in the first place. One way is to set a keep alive.

Related

Chromedriver closes after running nohup on google cloud

I have got a simple script which uses selenium and chromedriver. I have installed the chrome. When I run the script using the command nohup python3.7 -u main.py & tail -f nohup.out everything works; script works as it should. When I close the window of the google cloud ssh the scripts stop working. When I reopen the ssh and call tail -f nohup.out I receive such an error
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
(Session info: headless chrome=75.0.3770.142)
I was using the chrome version 87 and read that downgrading it should help, so I downgrade it to 75.
It is run on ubuntu, chrome and chromedriver version are 75. Is there such a command that would make chromedriver not close after closing the ssh window?
You can start processes in background in Linux. They will continue running even when you log off (which closing SSH window essentially is).
There are several ways:
Using bg & disown - as described here
Using screen as described here
You can go through entire thread to get more ideas. I'd recommend using bg & disown - it works well on Ubuntu provided by GCP however you can try out various solutions and pick the one that suits your needs the best.
From my experience - I was using screen for many things - including virtualbox and it worked - it may be more cumbersome if you want many processes to run in background but if that's just one its pretty easy.
Install screen: sudo apt install screen, run it with screen and treat it as another screen, run whatever you want and then just press ctrl + a d and you will be back to "original" shell. If you want to resume yor screen sessions type screen -r. You will find even more about using screen here.

Python program crashes when running in tmux session from boot

I have a python3 program that I run without any problems on a headless raspberry pi configuration where I connect using ssh. I logon to my pi, start a tmux session, and run the program. It will run indefinitely. During development when an exception would occur I the python program would terminate and I would see the error info.
Now if my pi were to reboot while I wasn't around I would want it to run this program automatically. I implemented the following steps to make this happen:
I created a script which contains this line:
tmux new-session -d -s xbnw 'python3 /home/pi/python/XbNWSer05.py'
Then I modified /etc/rc.local to include this line:
sudo -u pi bash /home/pi/tmux_xbnw.sh
Now when I reboot my pi everything works for a few minutes. The program is clearly running. I can logon and attach to the session and see my debug output and everything looks fine.
After a few minutes though something goes wrong and if I'm logged on and connected to the tmux session I suddenly find myself at a command prompt as though the program never ran. Also the tmux session is no longer active. There's no indication what happened.
1) Am I starting my program improperly?
2) If so is there a way to figure out what happened?
Add a logfile, either hacky by hand or with the logger module. Then you can find out if the programm started and you can log every minute or so to see when it dies and what was the last state.
You can also check the syslog whether there was a reboot. I had a bad power supply cable which made my Pi reboot in past...

How to terminate terminal that is connected to a AWS box but still leave process on?

I have ssh'd into a ubuntu AWS box via terminal on mac. I have successfully setup the process I want to run in the box.
How do can exit out of terminal without killing the process running?
Thank you in advance.
P.S
New to linux and terminal on mac
Personally I use screen to get in/out of the system while keeping the processes running.
$ sudo apt install screen
To create a new screen:
$ screen -S screen_name
Then do something in your screen, for example running a program, editing files, downloading file with wget, etc.
Later if you want to exit the terminal without killing the running process, simply press Ctrl+A+D.
The process will kept running in the background inside the screen
To reconnect to the screen:
$ screen -R screen_name

gearman stop start restart command

What are the command to start, restart and stop gearman?
So far I know:
gearadmin --shutdown # stop
gearmand -d # I believe it is to restart. Not sure.
Any idea for managing gearman?
If you want to restart the gearmand, then you should use the shell script gearman-job-server. Type the command as sudo service gearman-job-server restart which STOPs and STARTs the server
---------------------- More Information If you need it -----------------------
I assume you have some small confusion over here. It's all because of Terminologies. The name of the application is Gearman which is a Message-Queue System.
I am answering with the assumption tha you are working with Linux OS.
When you try installing the Gearman, the application that gets installed is gearmand which is a Job-Server/executable file. Something like Apache for example.
Refer the link http://manpages.ubuntu.com/manpages/precise/en/man8/gearmand.8.html for the command reference.
Then what's the gearman? gearman is the Client Program/Application, with which you can talk to the gearmand. With gearman you can run client and worker functions from the command line.
Refer the link http://manpages.ubuntu.com/manpages/precise/en/man1/gearman.1.html for the command reference.
So what's gearadmin? It's the tool which allows you to run Admin commands against your gearmand
Refer the link: http://manpages.ubuntu.com/manpages/precise/en/man1/gearadmin.1.html
Now coming to your questions about the command gearmand. From the shell if you run the command as gearmand, the Job Server starts and gets attached to your Shell Process. For ex: if you run php from shell the php runs and starts waiting for your commands right? Same way. If you want to run Gearmand as a background process, then you should run with the param as -d which makes it run as a daemon
So gearmand -d makes it run as Daemon. Not a restart command.
Hope this helps to answer your question and also to clarify in case if you have any confusion over the naming.
How to STOP Gearman Server
==> gearadmin --shutdown
How to START Gearman Server
==> gearmand -d
The popular answer seems to be a bit old, so if you get Failed to restart gearman-job-server.service: Unit not found. when trying to restart the old way, try just sudo service gearmand restart. That's how it seems to work on a CentOS with latest version of gearman.
For restarting the workers on the same system there seems to be a sudo gearmanw-control restart command avaliable.

how to run node js remotely

I am running node using putty. but it doesn't work when putty session expire. How can I start node js permanently, should not be terminated if putty session end.
I just solved that issue yesterday using Forever > http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever
It's awesome.
For Installing: npm install Forver
For running: forever start yourServer.js
For checking if its running: forever list
cool eh?
Generally you use a deamon to keep it running. A proper answer depends on what type of OS your remote machine is running (windows ?).
It's best to run node.js on *unix.
Among what Raynos and nEEbz are suggesting you can also try to use GNU Screen. This is very handy especially if you are using putty to connect to remote server. Check out this screen tutorial for more information.
Here is a quick and gentle introduction to "screen" .
In ubuntu, if you need to install it, use: apt-get install screen
First use:
$ screen
bunch of stuff prints out, then another shell prompt
$ node ./myapp.js
now your node app is running
You want to edit some other code?
control-a c
the window clears, and you now have another shell prompt. node is still running....
$ edit public/somewebfile.html
save it, still in editor
go back to node
control-a control-a
screen switches back to the screen running node
need to leave the office for a few minutes
control-a control-d
(screen detaches from your location... processes remain attached)
$ logout
screen disconnects, but nodejs and the editor are still running...
back at home... want to connect to work
> ssh work.some.where
> screen -D -R
screen reconnecting....
now you see the nodejs shell screen again, or control-a control-a to switch back to that editor
control-a ? shows available commands, or read the nice man page: man screen
You can also run nohup:
nohup node app.js
If you get an error when you do npm install Forever, do npm install forever -g
I got that problem.
https://www.npmjs.com/package/forever
Use PM2
just install pm2 on the server and run app like this : pm2 start app.js
you can also monitor your application from the web panel
PM2 (proccess manager)

Resources