Skip to content
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

Package and startup managed Metabase process #40

Merged
merged 1 commit into from
Oct 19, 2022
Merged

Conversation

pdobacz
Copy link
Collaborator

@pdobacz pdobacz commented Oct 19, 2022

Closes #37 and closes #10.

@@ -49,7 +49,7 @@ export const Services: FunctionComponent<ServicesProps> = ({ postgresql, metabas
</Space>
</div>
{/* Render next step */}
{metabase !== ServiceStatus.Starting && (
{postgresql !== ServiceStatus.Starting && (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes the table list and import GUI not wait for the lengthy Metabase start.

I tried digging for some tips on how to speed up MB, but nothing useful :(.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the Admin Panel doesn't need to wait for it, but query tabs will need to wait for the service to finish starting.

Comment on lines +384 to 392
if (aidColumns.length > 0) {
if (aidColumns.includes(rowIndexColumn)) {
await client.query(`ALTER TABLE "${tableName}" ADD COLUMN IF NOT EXISTS "${rowIndexColumn}" SERIAL`);
}
const aidColumnsSQL = aidColumns.map((aidColumn) => `'"${aidColumn}"'`).join(', ');
await client.query(`CALL diffix.mark_personal('"${tableName}"', ${aidColumnsSQL});`);
} else {
await client.query(`CALL diffix.mark_public('"${tableName}"');`);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this squashes two bugs:

  • the (not used for now, as explained in a previous PR comment) support for multi-AID columns was a series of mark_personal calls, which was some brainfart on my part
  • without calling public tables mark_public, Metabase wouldn't even see them. I probably didn't ever SELECT from them when testing and Metabase did that.

Comment on lines +34 to +39
MB_CHECK_FOR_UPDATES: 'false',
MB_PASSWORD_COMPLEXITY: 'weak',
MB_PASSWORD_LENGTH: '0',
MB_PLUGINS_DIR: metabasePluginsDir,
MB_SEND_EMAIL_ON_FIRST_LOGIN_FROM_NEW_DEVICE: 'false',
MB_SEND_NEW_SSO_USER_ADMIN_EMAIL: 'false',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bunch of MB settings which I think make sense for us. The password tweaks allow for a quick login, until the time we implement the disactivation of the login page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The password simplification is great. Nice find!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shame that even this combination of settings doesn't allow for an empty password 🤷. It seems a single letter password is as good as it gets

@pdobacz pdobacz marked this pull request as ready for review October 19, 2022 09:29
return;
} else {
console.info('Shutting down Metabase...');
metabase?.kill();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually isn't too graceful on Linux (error code 143 and some stderr output), but for now fixing this isn't a priority

gui/build.win.js Outdated Show resolved Hide resolved
@@ -49,7 +49,7 @@ export const Services: FunctionComponent<ServicesProps> = ({ postgresql, metabas
</Space>
</div>
{/* Render next step */}
{metabase !== ServiceStatus.Starting && (
{postgresql !== ServiceStatus.Starting && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the Admin Panel doesn't need to wait for it, but query tabs will need to wait for the service to finish starting.


export async function shutdownMetabase(metabase?: ChildProcess): Promise<void> {
if (isWin) {
// No graceful way to shutdown Metabase on Windows, let the OS handle it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a kill either way, so you can leave the code cross-platform until we find a workaround.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it turns out, when packaged in an exe the metabase service doesn't shutdown by itself. So I'm forced to fix it in the next PR

postgresql?.kill();
if (isWin) {
// If we let the OS handle shutdown, it will not be graceful, and next start is in recovery mode.
asyncExecFile(path.join(postgresBinPath, 'pg_ctl'), ['-w', '-D', dataDirPath, 'stop']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm very confused why and how this works... Signals don't work on Windows, so the process should still be killed abruptly, see the code in pg_ctl here.

I have been playing with this for most of the day and I couldn't find a satisfactory solution from inside node.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, this should work on Linux as well, so maybe no need to have separate code paths?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, I now got it: kill is defined as a custom call on Windows which does IPC.
So much time I wasted in vain on this...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit, I didn't dig that deep. It worked and seemed like the recommended way (somewhere in pg docs), so I went with it.

Per Linux... I don't remember 😅 . I'm revisiting this somewhat for the next PR, so I'll login back to linux and check there. If we have no issues with using pg_ctl in general, then I have no objections towards a common path for win/linux

@pdobacz pdobacz merged commit 2a5b73a into main Oct 19, 2022
@pdobacz pdobacz deleted the piotr/start-metabase branch October 19, 2022 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Metabase to packaging script Add procedure for launching Metabase on startup.
3 participants