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

Check nginx install without dpkg #853

Closed
enguerran opened this issue Nov 6, 2018 · 6 comments
Closed

Check nginx install without dpkg #853

enguerran opened this issue Nov 6, 2018 · 6 comments

Comments

@enguerran
Copy link

Summary

Regarding https://github.com/TryGhost/Ghost-CLI/blob/master/extensions/nginx/index.js#L282

    isSupported() {
        try {
            execa.shellSync('dpkg -l | grep nginx', {stdio: 'ignore'});
            return true;
        } catch (e) {
            return false;
        }
    }

We check Nginx by using a third-party command called dpkg that is available only on Debian-based distributions.
I use Arch linux and I have nginx installed. I can check it with

    isSupported() {
        try {
            execa.shellSync('nginx -v', {stdio: 'ignore'});
            return true;
        } catch (e) {
            return false;
        }
    }

Then the command ghost setup nginx can do everything it needs:

/v/w/ghost> ghost setup nginx
✔ Creating nginx config file at /var/www/ghost/system/files/servername.conf
+ sudo ln -sf /var/www/ghost/system/files/servername.conf /etc/nginx/sites-available/servername.conf
+ sudo ln -sf /etc/nginx/sites-available/servername.conf /etc/nginx/sites-enabled/servername.conf
+ sudo nginx -s reload
✔ Setting up Nginx

Can we not consider using nginx -v to check for the presence of nginx?

@acburdine
Copy link
Member

@enguerran that's a possibility, however it might be a little tricky as nginx by default (at least in Ubuntu) is installed in /usr/sbin which (if I recall correctly) isn't appended to the $PATH of a user by default. We'd have to manually append it, which is doable but increases complexity.

@enguerran
Copy link
Author

After an update, I find this error on my Arch Linux server (which doesn't have dpkg -l to search if nginx is installed).

I thought that maybe one solution was to ask the user if we skip or not after isSupported returned false. Because in the end, in the following, we consider that nginx is in the PATH or provided via the environment variable.
https://github.com/TryGhost/Ghost-CLI/blob/master/extensions/nginx/index.js#L275

The solution may be something like this

return promise.catch((error) => {
ctx.ui.log(
`System checks failed with message: '${error.message}'
Some features of Ghost-CLI may not work without additional configuration.
For local installs we recommend using \`ghost install local\` instead.`,
'yellow'
);
return ctx.ui.confirm(chalk.blue('Continue anyway?'), false).then((confirmed) => {
if (confirmed) {
task.skip('System stack check skipped');
return Promise.resolve();
}
return Promise.reject(new errors.SystemError({
message: `System stack checks failed with message: '${error.message}'`,
task: taskTitle
}));
});
});

I can write the code needed using inquirer if the proposotion is accepted.

@acburdine
Copy link
Member

@enguerran I'm working on some improvements to these checks - should have something out soon.

acburdine added a commit to acburdine/Ghost-CLI that referenced this issue Oct 9, 2020
refs TryGhost#853,TryGhost#1265
- refactor system stack check to use systeminformation to check support
- update ubuntu allowed versions to support Ubuntu 20
acburdine added a commit that referenced this issue Oct 9, 2020
refs #853,#1265
- refactor system stack check to use systeminformation to check support
- update ubuntu allowed versions to support Ubuntu 20
@acburdine
Copy link
Member

acburdine commented Oct 9, 2020

@enguerran I've refactored the stack check to use systeminformation's services utility to check if nginx is installed by iterating over the list of installed services, rather than distro-specific command like dpkg.

This change will be released with Ghost-CLI 1.15.0.

@enguerran
Copy link
Author

Thank you very much @acburdine for following up on this modification request which is clearly not proprietary but which I am very pleased with!

@amo13
Copy link

amo13 commented Oct 2, 2021

Unfortunately, I am still having this issue on Archlinux with ghost-cli 1.17.3. Did anything in the detection mechanism change again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants