How to use sudo to run brew services stop mysql as non root user in script running as root
Hi,
This is a bit of a curly one. I need to run the brew services command to stop mysql in a script running as root. The problem is that command should not be run as the root user and so I am trying to use the -u and -i flags on the sudo command for:
sudo -u <username> -i brew services stop mysql@5.7
Unfortunately, this results in the output of:
Error: Service mysql@5.7 is not started.
This is true as far as the root user is concerned as #brew services will produce:
mysql@5.7 stopped
However, when you drop down to the user where the mysql@5.7 service was started from, it is still running.
What am I doing wrong here? Can anyone help? I’ve posted this on Apple Stack Exchange with no response so far :/
Thanks,
GAM
Mac mini, macOS 10.13