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?