LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2015, 02:48 PM   #1
periz
LQ Newbie
 
Registered: Apr 2010
Posts: 5

Rep: Reputation: 0
script for program update and restart


I developed an application in Matlab and I compiled it in Linux.
My application can check for updates online and download them.
The aim is to have the updates installed and to restart the application (automatically).
The installation consists basically just in unzipping the code and replace the current one with the new one.
I thought to have Matlab write a bash script and then launch it to install the code and then restart. However I cannot understand why it cannot restart.

The bash script I wrote makes the following operations (files are already unzipped from within Matlab):
- it kills the current application (so that it can be replaced by the new one)
- it moves the unzipped files from a temporary directory to the target directory replacing the old files
- it removes the temporary directory
- it calls the new executable (in fact, it's calling a bash script which launches the Matlab compiled application)

The bash script I wrote is correctly launched. In fact, it kills the current application, it replaces the files and it removes the temporary directory. However, the new executable is not executed.

I tried using exec, or opening a new xterm with the new application, or using disown or nohup, no luck in any case.

If I launch the script manually, it correctly calls the new executable. But if it is launched from within the old application, it does not work (or better: as I said only some operations are executed).

Here the script:
#!/bin/sh
kill -9 $(pidof main)
mv -f /periz/matlab/compiled-linux/archive/tmp/* /periz/matlab/compiled-linux/
rmdir /periz/matlab/compiled-linux/archive/tmp
/periz/matlab/compiled-linux/run_main.sh /usr/local/MATLAB/MATLAB_Compiler_Runtime/v83

What am I missing?

Many thanks!!!

Last edited by periz; 04-27-2015 at 10:11 AM. Reason: I'm adding the code
 
Old 04-27-2015, 10:11 AM   #2
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
Are you forking and calling setsid before launching the script? You're killing the parent session if you aren't, which I would guess is the problem.
 
Old 04-27-2015, 10:27 AM   #3
periz
LQ Newbie
 
Registered: Apr 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the answer.

I'm going to try it soon!
 
Old 04-27-2015, 12:25 PM   #4
periz
LQ Newbie
 
Registered: Apr 2010
Posts: 5

Original Poster
Rep: Reputation: 0
so, this is the case.
sorry that I'm still not well understanding how it works.
I modified the code as follows, and I tried to put "fork()" at positions (a) (b) and (c)

#!/bin/sh
(a)
kill -9 $(pidof main)
(b)
mv -f /periz/matlab/compiled-linux/archive/tmp/* /periz/matlab/compiled-linux/
rmdir /periz/matlab/compiled-linux/archive/tmp
(c)
setsid /periz/matlab/compiled-linux/run_main.sh /usr/local/MATLAB/MATLAB_Compiler_Runtime/v83

If I place it at (a), the old application will not be killed. If I place it at (b), the old code will not be replaced with the new one. Finally, if I place it at (c), the new application will not start

What is the ratio behind?
Thanks again
 
Old 04-27-2015, 12:54 PM   #5
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
Actually, when I said before launching the script I meant in your application. It is the parent of the script. I don't program in matlab so don't know if it has the facilities to do this. The rational is to fork a process and then separate it from the parent process since you are going to kill the parent.
 
Old 04-27-2015, 10:06 PM   #6
periz
LQ Newbie
 
Registered: Apr 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks, I got it!
Now it works!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to restart a program at a given different interval Jajamd Programming 4 12-28-2011 05:23 PM
Bash script to restart a dead script nathanpayne Programming 9 07-22-2011 10:28 PM
Restart a program sibtay Programming 4 09-28-2004 10:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration