VirtualBox headless auto start & ports

dgz

Supreme [H]ardness
Joined
Feb 15, 2010
Messages
5,838
This noobster needs help.

I have spun an Ubuntu Server 18.04 for the purpose of running Quake Live, and other game servers, via the LinuxGSM utility. Yeah, setting up Quake 3 server way simpler. Everything has gotten too complex :/

Said OS is living inside an updated VirtualBox (6.1) on a Ryzen 3700 based host running regular Ubuntu 18.04. In the VM, I have created a systemd service which runs the sh script spawning the server, and allowed the necessary UDP ports in VBox. I have also created another systemd service on the host itself, which starts the VM in headless mode via the following

Code:
/bin/su -s /bin/bash -c 'VBoxManage startvm "GSM" --type headless' htpc

At first, everything seemd to be working fine: the VM starts, the server inside is up and running, people can connect and play. Manually starting it is fine.

But here's the deal: no one, including me, can connect to the game server if the VM has been started automatically via the aforementioned systemd service on the host. I can log in to the machine, the game server is running, everything else seems to be running, except there seems to be some kind of networking problem.

Running the same script, that systemd starts, manually: everything's fine.
Running it automatically on boot: no go.

I wasted my entire Saturday afternoon setting up everything and I have nothing to show for it. It makes no sense.
 
Are you starting your service from the CLI as root when you run it or a non root user? I know it sounds stupid, but there is a big difference between su and su - root. Using just su takes in the current environmental profiles of the user running the su command. Doing an su - means the process will refresh the environmental profile of whats defined for the root user over writing anything currently in memory.

Try this..

Change your command to look like this:

Code:
 /bin/su - root -s /bin/bash -c 'VBoxManage startvm "GSM" --type headless' htpc

and try again.

If that kiiinnnnda works, then its an environmental issue..

When you run the command manually, take note of which user you are. If you logged in as you and then switched to the root user, make note as to how you switched to the root user.

Example. You logged in the system as user: gamer
You want to switch to the root user and you run this command to do it: su root
You will switch to the root user, but that session will inherit any custom environmental variables you set in your .profile. If you modded the user gamer's profile for "things", the root user will inherit those environmental settings.

Example. You logged into the system as user: gamer
You want to switch to the root user and your run this command to do it: su - root
You will switch to the root user, but that session will refresh all environmental variables from /etc/profile and anything set in roots home dir.

Do this.. before you start the process manually from the CLI with your current work flow, do an echo $PATH and save the output to a text file.

then do a su - root
Then do a PATH=$PATH:<and paste int the output from the previous echo $PATH in here> ; export PATH and then try and start your process. see if it works.

One more bit.. I've run into issues where a service that needs network is starting before the os networking service has finished starting.

Move the startup of your process to the very end of your system startup process.
 
  • Like
Reactions: dgz
like this
Code:
VBoxManage: error: Could not find a registered machine named 'GSM'
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "FindMachine(Bstr(pszVM).raw(), machine.asOutParam())" at line 722 of file VBoxManageMisc.cpp

this is what I get when I try to execute the bash script. I don't get it. Works fine withh

Code:
/bin/su -s /bin/bash -c 'VBoxManage startvm "GSM" --type headless' htpc
 
Looks like the path issue kdh mentioned. Have you tried his suggestion regarding networking and startup order?
 
Pretty obvious.. You are trying to start a machine the executable knows nothing about. You didn't update your path statements like I suggested. You are still starting the executable with YOUR environmental variables set. You need to set the same ones for the root user. Reread what I wrote about su - root vs su root.
 
Back
Top