Perl Script Is Hanging With Tomcat Server [duplicate] - linux

This question already has answers here:
How can I run Perl system commands in the background?
(4 answers)
Closed 8 years ago.
I am running a Perl script in which I need to start a tomcat server. After starting the server I need to execute a different linux command.
In the Perl script after starting tomcat it isn't coming out to the next line as tomcat sever is running..
system("tomcat.sh run >log.txt");
system("ls");
I tried to open the server in different terminal. But control remains there itself.
system("xterm", "-hold", "-e", " tomcat.sh run");
I tried exec in place of system but the behaviour is same.

If you use the single string version of system then you can append an & to run your command in the background:
system("tomcat.sh run >log.txt &");
Should do the trick.
I also found a similar question here

This is because system blocks until the process finishes. I'm not sure on how to deal with such situation, you might fork it, close STDIN before you run external process etc. Instead of system, you might try IPC::System::Simple, which handles a lot of platform-specific details for you, or modules like IPC::Run or IPC::Open3.
Similar to your issue: Why does my jzip process hang when I call it with Perl's system?

Related

How to run a shell which will stop current process? [duplicate]

This question already has answers here:
Make child process spawned with system() keep running after parent gets kill signals and exits
(2 answers)
Closed 3 years ago.
The program processA is a Linux service, launched by "systemctl start processA".
This process will call std::system to run a shell script to upgrade software.
The script will run "systemctl" to stop processA first, then replace some executable files, finally restart processA.
The problem is that when "systemctl stop processA" is executed, the script is also terminated.
How to solve it?
I had tried to run the script file in terminal; it works. So there is not a problem with the script.
//this is how the script is called
int rs = std::system("/usr/bin/update_server.sh upgrade \"/tmp/firmware\" > \"/tmp/upgrade.log\" 2>&1");
systemd will also kill child processes (after all, that's what's usually desired), so you can't do the upgrade from the service.
You can, however create a oneshot service to upgrade the binary that conflicts with the main service. To upgrade, you stop the service, run the upgrade service and then start the service again.

How to set up a bash script to run in the background anytime the linux ubuntu server is running

I have written up a simple bash script that will copy the newest image from my ip camera into a directory, rename the file and delete the old file. The script loops every 10 seconds.
I want to have this script start running in the background and run continuously all the time that the server is up.
I understand the part about adding a & to the end of the command will cause it to run in the background.
Is init.d the best place to execute this?
I am running ubuntu server.
This sort of thing is normally done by service scripts, which you would find under /etc/init.d. Depending on the version, that might be a "System V init script", or one of the systemd scripts.
A simple service script of the sort you are asking about would start automatically (based on comments in the script's header that tell what run-levels it would use), create a file under /var/run telling what process-id the script uses (to allow killing it), and run the copying in a loop, calling sleep 10 to space the timing as indicated.
A typical service script should implement "start", "stop", "restart" and "status". Not all do, but there is rarely a good reason to not do this.
On my (Debian) system, there is a README file in the directory which is a good introduction to the topic. There are several tutorials available for the topic. Here are a few:
Linux: How to write a System V init script to start, stop, and restart my own application or service
Writing a Linux Startup Script
Manage System Startup and Boot Processes on Linux with Upstart

linux running program to be shown again when console closed unfortunately

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.

Running my application after all boot up process

i want to run my application on board(i.MX233 EVK) after all modules loaded.i want to add auto log-in.i got this link but the procedure not working.
Running a script after startx automatically
where can i add small script to load my application(C language) automatically after boot-up of board.
Your question has been literally answered million times on Internet. Please have a look at How to run a shell script at startup for instance.
Put your script in /etc/init.d/rcS or rc file init process will automatically execute it.
/etc/init.d/rcS
your_script.sh &

On OpenSuSE (or linux in general) where should a non-service startup script go?

On an OpenSuSE linux machine, I want to run a script when the machine is booted. As the script does not start a service, is /etc/rc.d the correct place for the script?
Thanks.
That's where I've always put them. There are several scripts in rc.d already which don't actually start a process. However, you need to write it in a similar fashion to the other startup scripts - have a look at a few to see how they are set up. Specifically, you should make sure that it's possible to run the script using /etc/rc.d/myscript start.

Resources