-
Notifications
You must be signed in to change notification settings - Fork 0
Using files to store pid and refactor processes termination #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/main/ipfs.ts
Outdated
| if (pid) { | ||
| await removePidFile(); | ||
| logger.log('Shutting down the IPFS daemon'); | ||
| await rpcRequest('shutdown'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
execSync(process.platform === 'win32' ? 'ipfs.exe shutdown' : '.synthetix/go-ipfs/ipfs shutdown')There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/main/follower.ts
Outdated
| // whatever | ||
| const pid = readFileSync(PID_FOLLOWER_FILE_PATH, 'utf8'); | ||
| if (pid) { | ||
| rmSync(PID_FOLLOWER_FILE_PATH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| rmSync(PID_FOLLOWER_FILE_PATH); | |
| rmSync(path.join(ROOT, 'ipfs-cluster-follow.pid'), {force: true}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PID_FOLLOWER_FILE_PATH removed
src/main/follower.ts
Outdated
| if (process.platform === 'win32') { | ||
| execSync(`taskkill /F /PID ${pid}`); | ||
| } else { | ||
| process.kill(Number(pid)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process.kill as native nodejs method should be cross-platform
| if (process.platform === 'win32') { | |
| execSync(`taskkill /F /PID ${pid}`); | |
| } else { | |
| process.kill(Number(pid)); | |
| } | |
| process.kill(Number(pid)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right when I caught some error and thought that process.kill() only was the Unix system. I was wrong.
src/main/follower.ts
Outdated
| logger.log(`follower kill: PID ${pid} killed and PID file removed`); | ||
| } | ||
| } catch (e) { | ||
| logger.log('follower kill error:', e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.error(e)
But logging is not working during shutdown so probably not much sense to have it at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
| } catch (_error) { | ||
| logger.log(`followerId: `, _error); | ||
| return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } catch (_error) { | |
| logger.log(`followerId: `, _error); | |
| return ''; | |
| } catch (error) { | |
| logger.error(error); | |
| return ''; |
Guess these are just debugging things for draft anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly, removed
src/main/ipfs.ts
Outdated
| rmSync(path.join(IPFS_PATH, 'repo.lock'), { recursive: true }); | ||
| } catch (_e) { | ||
| // whatever | ||
| if (readFileSync(PID_IPFS_FILE_PATH, 'utf8')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for if. just do rmSync(PID_IPFS_FILE_PATH, {force: true}); - it will not fail even if file does not exist.
Also only delete PID and repo.lock after IPFS was shut down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- removed if()
- removed PID_IPFS_FILE_PATH const
- moved file deletion after the shutdown. BUT, I moved them up for a reason, because the files were not deleted when I interrupted the execution of the program (server) with the keyboard Ctrl+C. I don't know if this case is important for us or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like node process does not wait for ipfs to fully shutdown? I can see you moved rm after shutdown - did it work this time?
I reckon we cannot remove ipfs locks until ipfs if fully off anyway. We could do that with PID.
If there are issues - the order can be
- remove pid
- shutdown ipfs
- remove locks
src/main/main.ts
Outdated
| ipcMain.handle('follower-isInstalled', followerIsInstalled); | ||
| ipcMain.handle('ipfs-isRunning', ipfsIsRunning); | ||
| ipcMain.handle('follower-isRunning', followerPid); | ||
| ipcMain.handle('follower-isRunning', () => getPid(PID_FOLLOWER_FILE_PATH)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ipcMain.handle('follower-isRunning', () => getPid(PID_FOLLOWER_FILE_PATH)); | |
| ipcMain.handle('follower-isRunning', () => fs.readFile(path.join(ROOT, 'ipfs-cluster-follow.pid'), 'utf8').catch(() => null)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed getPid()
src/main/follower.ts
Outdated
| ? 'ipfs-cluster-follow.exe' | ||
| : '.synthetix/ipfs-cluster-follow/ipfs-cluster-follow synthetix run' | ||
| ); | ||
| const pid = await getPid(PID_FOLLOWER_FILE_PATH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const pid = await getPid(PID_FOLLOWER_FILE_PATH); | |
| const pid = await fs.readFile(path.join(ROOT, 'ipfs-cluster-follow.pid'), 'utf8').catch(() => null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed pid.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great
* Using files to store pid and refactor processes termination (#2) * Using files to store pid and refactor processes termination * Refactor process termination * Update logging message during IPFS daemon termination * Refactor process termination and returned getPid async * Deleting a file before processes are terminated * Fix review comments * Add to fs.readFile to catch errors handler * Transition to Electron Forge * Replace npm with yarn in config.yml * Add dpkg and fakeroot dependencies in CircleCI config * Add rpm to CircleCI configuration * Convert PNG icon into a true ICO icon * Linux support * Remove compiled code * Enable global yarn cache * Lint script * Lint harder * Fix `make` in CCI * Renames * Update building and packaging * Update deps * Fix for empty args * Support ipns codec * No need to tear down * Return config * Return icons * Add back svg and config checks * Update readme for config pinning * Fix teardown * Return svg icons * Remove node-fetch * Lint harder * Fix typo * Package not make --------- Co-authored-by: Noisekit <nikita@cc.snxdao.io>
* Using files to store pid and refactor processes termination (#2) * Using files to store pid and refactor processes termination * Refactor process termination * Update logging message during IPFS daemon termination * Refactor process termination and returned getPid async * Deleting a file before processes are terminated * Fix review comments * Add to fs.readFile to catch errors handler * Fix dock icon on macOS * Add custom app icons configuration and DPI support * Update icon paths in forge config and icons generator * Remove hardcoded paths to app icons * Remove generation icon.ico from icongen.js * Run app.dock.setIcon() only for development mode * Add app icon for develop mode * Replace __dirname with app.getAppPath()
* Using files to store pid and refactor processes termination (#2) * Using files to store pid and refactor processes termination * Refactor process termination * Update logging message during IPFS daemon termination * Refactor process termination and returned getPid async * Deleting a file before processes are terminated * Fix review comments * Add to fs.readFile to catch errors handler * Add authentication flow - first commit * Add authentication flow - first commit * Fix signMessage * Add if condition for signedMessage * Add token management and UI signing feedback * Add application mutation hooks and AccessControl component * Remove unused icon URL and adjust footer alignment * Add FormControl for input validation * Add localhost API URL and success callbacks * Refactor fetch logic to a reusable function * Remove unused approval/rejection logic * Refactor headers * Remove boxShadow * Add environment variable support with dotenv * Add React Router for navigation * Add RPC URL * Add NetworkMismatch component * Remove unused URL and adjust main window height * Apply suggestions from code review --------- Co-authored-by: Noisekit <28145325+noisekit@users.noreply.github.com>
No description provided.