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

Composer service (HMS-5455) #2847

Merged
merged 4 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/AppCockpit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ import { createRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import { HashRouter } from 'react-router-dom';

import { NotReady } from './Components/Cockpit/NotReady';
import { Router } from './Router';
import { onPremStore as store } from './store';
import { useGetComposerSocketStatus } from './Utilities/useComposerStatus';

const Application = () => {
const { enabled, started } = useGetComposerSocketStatus();

if (!started || !enabled) {
croissanne marked this conversation as resolved.
Show resolved Hide resolved
return <NotReady enabled={enabled} />;
}

return (
<React.Fragment>
<NotificationsPortal />
Expand Down
61 changes: 61 additions & 0 deletions src/Components/Cockpit/NotReady.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';

import {
Button,
EmptyState,
EmptyStateActions,
EmptyStateBody,
EmptyStateFooter,
EmptyStateIcon,
EmptyStateVariant,
Title,
} from '@patternfly/react-core';
import { CubesIcon } from '@patternfly/react-icons';
import cockpit from 'cockpit';

export const NotReady = ({ enabled }: { enabled: boolean }) => {
return (
<EmptyState variant={EmptyStateVariant.xl}>
<EmptyStateIcon icon={CubesIcon} />
<Title headingLevel="h4" size="lg">
OSBuild Composer is not {enabled ? 'started' : 'enabled'}
</Title>
<EmptyStateBody />
<EmptyStateFooter>
<EmptyStateActions>
<Button
variant="primary"
onClick={(event) => {
event.preventDefault();
cockpit
.spawn(
['systemctl', 'enable', '--now', 'osbuild-composer.socket'],
{
superuser: 'require',
err: 'message',
}
)
.then(() => window.location.reload());
}}
>
Start socket
</Button>
</EmptyStateActions>
<EmptyStateActions>
<Button
variant="link"
onClick={(event) => {
event.preventDefault();
cockpit.jump(
'/system/services#/osbuild-composer.socket',
cockpit.transport.host
);
}}
>
More Info
croissanne marked this conversation as resolved.
Show resolved Hide resolved
</Button>
</EmptyStateActions>
</EmptyStateFooter>
</EmptyState>
);
};
44 changes: 44 additions & 0 deletions src/Utilities/useComposerStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useEffect, useState } from 'react';

import cockpit from 'cockpit';

export const useGetComposerSocketStatus = () => {
const [enabled, setEnabled] = useState(false);
const [started, setStarted] = useState(false);

useEffect(() => {
const isEnabled = async () => {
try {
const result = await cockpit.spawn(
['systemctl', 'is-enabled', 'osbuild-composer.socket'],
{ superuser: 'try' }
);
setEnabled((result as string).trim() === 'enabled');
} catch {
// error code 1 means disabled
setEnabled(false);
}
};

const isStarted = async () => {
try {
const result = await cockpit.spawn(
['systemctl', 'is-active', 'osbuild-composer.socket'],
{ superuser: 'try' }
);
setStarted((result as string).trim() === 'active');
} catch {
// exit code 3 means not active
setStarted(false);
}
};

isEnabled();
isStarted();
}, []);

return {
enabled,
started,
};
};
Loading