0

I am trying to run executable from bash script. Executable is nodejs app packaged with zeit-pkg.

What I am doing:

Run child process. Child process kills parent, replaces the app with the new version and runs app again.

const fileName = './run_install';
const dir = 'temp';
const runInstall = spawn(
  fileName, [],
  {
    cwd: process.cwd() + '/' + dir,
    detached: true,
    stdio: 'ignore'
  }
);
runInstall.unref();

Everything works with javascript files and npm start

My ./run_install script for javascript file

sleep 1s
kill -9 $(pgrep node)
sleep 1s
mkdir ../old_versions
mv ../server.js ../old_versions/server.js.old
mv server.js ../
cd ../
npm start & rm -r ./temp & exit 0

But when I try to do the same thing with executable, new version of app is not started. the line ./imac & just ignored.

My ./run_install script for executable

#!/bin/bash
sleep 1s
kill -9 $(pgrep imac)
sleep 1s
mkdir ../old_versions
mv ../imac ../old_versions/imac.old
mv imac ../
mv rollback ../
cd ../
chmod 755 ./imac
chmod 755 ./rollback
./imac &
rm -r ./temp & exit 0

How can I run my executable?

Community
  • 1
  • 1
AlbertS
  • 706
  • 5
  • 12
  • First thing I would do is start using fully qualified path names. – miken32 Dec 20 '18 at 23:45
  • path names are good. the pkg executable is not runnable from script. I can run ordinary script from script but not this pkg. – AlbertS Dec 21 '18 at 04:55
  • Solved partially. I killed the process by name. So if I give the executable new name, i.e. imac1 and run it ./imac1, everything is working. – AlbertS Dec 21 '18 at 05:32

0 Answers0