Page MenuHomePhabricator

Tools may not allow non-interactive commands via 'become' due to dotfile configuration
Open, LowPublic

Description

While working on parent task and roll-restarting all webservices I noticed become <tool> <command> not always works as intended, i.e. command gets executed and become returns.

Instead, the user is dropped into a shell prompt and upon exiting then the command is run. In other words, a shell is run interactively and upon exiting that shell then the command is run.

root@tools-bastion-14:~# become mp ls
.-(~)---------------------------------------------------------------------------------------------------------------(tools.mp@tools-bastion-14)-
`--> exit
bin  bootstrap_venv.sh  error.log  logs  mp  public_html  replica.my.cnf  service.manifest  toolforge_jobs.yaml

I noticed this because the roll-restart stopped until I intervened and exited the shell. I have experienced this for mp and spbot. My expectation is that become can always run commands non-interactively, what do you think ?

Event Timeline

My expectation is that become can always run commands non-interactively, what do you think ?

The /data/project/mp/.profile dotfile is breaking the workflow you expect.

/data/project/mp/.profile
# start zsh
/bin/zsh

This profle hijacks the normal shell initialization flow to start a new interactive sub-shell. It would be more ideal if the tool used the method documented in T186108#3938059 to exec zsh if an only if an interactive shell is being entered:

$HOME/.bash_profile
[[ "$-" == *i* ]] && exec /usr/bin/zsh

@Euku and @Ireas, I fixed the issue that @fgiunchedi noticed with your mp tool by applying the pattern from T186108#3938059. I did roughly these actions:

$ mv .profile .profile-T426378
$ cat > .bash_profile <<'EOF'
# T186108: Replace bash with zsh in interactive shells
[[ "$-" == *i* ]] && exec /usr/bin/zsh
EOF
$ echo "export SHELL=/usr/bin/zsh" >> .zshrc

The result:

bd808@tools-bastion-14.tools.eqiad1:~$ sudo become mp -- ls
bin                logs         replica.my.cnf
bootstrap_venv.sh  mp           service.manifest
error.log          public_html  toolforge_jobs.yaml
bd808@tools-bastion-14.tools.eqiad1:~$ sudo become mp
.-(~)-----------------------------------------------(tools.mp@tools-bastion-14)-
`--> echo $0
/usr/bin/zsh
.-(~)-----------------------------------------------(tools.mp@tools-bastion-14)-
`--> exit
bd808@tools-bastion-14.tools.eqiad1:~$

@Euku I made the same changes for your spbot tool as well.

bd808 renamed this task from Tools may not allow non-interactive commands via 'become' to Tools may not allow non-interactive commands via 'become' due to dotfile configuration.Fri, May 15, 4:42 PM

Thank you @bd808 for the fix and digging up T186108, definitely not a new problem!

aputhin added a project: tools-platform-team.
aputhin subscribed.

We can take a look at a better fix for this edge case, but it doesn't seem like an urgent problem / widespread issue.