Skip to content

Commit

Permalink
improve linux setup stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Nov 26, 2024
1 parent 4f1604f commit 92e5dd6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
20 changes: 1 addition & 19 deletions hooks/lando-autostart-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,8 @@ module.exports = async lando => {
delay: 1000,
},
task: async (ctx, task) => {
// Prompt for sudo password on linux
if (lando.config.os.landoPlatform === 'linux' && lando.config.isInteractive) {
ctx.password = await task.prompt({
type: 'password',
name: 'password',
message: `Enter computer password for ${lando.config.username} to start docker`,
validate: async (input, state) => {
const options = {debug, ignoreReturnCode: true, password: input};
const response = await require('../utils/run-elevated')(['echo', 'hello there'], options);
if (response.code !== 0) return response.stderr;
return true;
},
onCancel() {
process.emit('SIGINT');
},
});
}

try {
await lando.engine.daemon.up(false, ctx.password);
await lando.engine.daemon.up(false);
await lando.shell.sh([`"${lando.engine.daemon.docker}"`, 'network', 'ls']);
} catch (error) {
ctx.errors.push(error);
Expand Down
11 changes: 10 additions & 1 deletion hooks/lando-setup-build-engine-linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ module.exports = async (lando, options) => {
hasRun: async () => {
// start by looking at the engine install status
// @NOTE: is this always defined?
return lando.engine.dockerInstalled;
if (lando.engine.dockerInstalled === false) return false;

// if we get here let's make sure the engine is on
try {
await lando.engine.daemon.up({max: 1, backoff: 1000});
return true;
} catch (error) {
lando.log.debug('docker install task has not run %j', error);
return false;
}
},
canRun: async () => {
// throw if we cannot resolve a semantic version to a buildid
Expand Down
2 changes: 1 addition & 1 deletion lib/art.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ exports.newContent = (type = 'guide') => [
'',
].join(os.EOL);

exports.setupHeader = (bengine = process.landoPlatform ?? process.platform === 'linux' ? 'Engine' : 'Desktop') => `
exports.setupHeader = (bengine = process.landoPlatform === 'linux' || process.platform === 'linux' ? 'Engine' : 'Desktop') => `
${chalk.magenta(niceFont('Lando Setup!', 'Small Slant'))}
${chalk.bold('lando setup')} is a hidden convenience command to help you satisify the
Expand Down
3 changes: 2 additions & 1 deletion lib/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ module.exports = class LandoDaemon {
break;
case 'linux':
const lscript = path.join(this.scriptsDir, 'docker-engine-start.sh');
await require('../utils/run-elevated')([lscript], {debug, password});
if (password) await require('../utils/run-elevated')([lscript], {debug, password});
else await require('../utils/run-command')(lscript, {debug});
break;
case 'win32':
case 'wsl':
Expand Down
16 changes: 15 additions & 1 deletion scripts/docker-engine-start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/sh
set -e

systemctl start docker.service || service docker start
# Function to check if a Polkit agent is running
is_polkit_agent_running() {
ps aux | grep -q "[p]olkit" && return 0 || return 1
}

# Check if the DISPLAY or XDG_SESSION_TYPE indicates a desktop environment
if [ -n "$DISPLAY" ] || [ "$XDG_SESSION_TYPE" = "x11" ] || [ "$XDG_SESSION_TYPE" = "wayland" ]; then
if is_polkit_agent_running; then
systemctl start docker.service || service docker start
else
sudo systemctl start docker.service || sudo service docker start
fi
else
sudo systemctl start docker.service || sudo service docker start
fi
2 changes: 1 addition & 1 deletion utils/shutdown-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = ({
message = 'Lando wants to restart your computer',
password = undefined,
type = 'restart',
wait = process.landoPlatform ?? process.platform === 'win32' ? 5 : 'now',
wait = process.landoPlatform === 'win32' || process.platform === 'win32' ? 5 : 'now',
platform = process.landoPlatform ?? process.platform,
} = {}) => {
debug('shutdown with %o %o', type, {message, wait});
Expand Down

0 comments on commit 92e5dd6

Please sign in to comment.