Tiiffi / mcrcon

Rcon client for Minecraft
https://github.com/Tiiffi/mcrcon/
zlib License
834 stars 116 forks source link

Environment variables don't work #77

Closed sugoidogo closed 2 years ago

sugoidogo commented 3 years ago

Both in systemd and via bash script I can't get mcrcon to recognize my environment variables unless I export them, which systemd doesn't do. This is non-standard behavior for reading environment variables, which means they can't be used with systemd.

root@minecraft:~# MCRCON_PORT=25575
root@minecraft:~# MCRCON_PASS=password
root@minecraft:~# echo $MCRCON_PORT $MCRCON_PASS
25575 password
root@minecraft:~# mcrcon
You must give password (-p password).
Try 'mcrcon -h' or 'man mcrcon' for help.
root@minecraft:~# export MCRCON_PORT
root@minecraft:~# export MCRCON_PASS
root@minecraft:~# echo $MCRCON_PORT $MCRCON_PASS
25575 password
root@minecraft:~# mcrcon
Connection failed.
Error 111: Connection refused

I was expecting Connection failed on the first run of mcrcon, got You must give password (-p password). instead.

Hagb commented 3 years ago

It is not about mcrcon. In bash, MCRCON_PORT and MCRCON_PASS in this case hadn't been environment variables until export was used for them. The behavour in this case is actually what should happen.

The following command can also be used for running mcrcon with this two environment variables temporarily set:

MCRCON_PORT=25572 MCRCON_PASS=password mcrcon
sugoidogo commented 3 years ago

What about systemd? I have a unit file:

...
EnvironmentFile=/opt/minecraft/.env
...
ExecStop=mcrcon save-all stop
...

/opt/minecraft/.env:

MCRCON_PORT="25575"
MCRCON_PASS="password"
Hagb commented 3 years ago

What about systemd? I have a unit file:

...
EnvironmentFile=/opt/minecraft/.env
...
ExecStop=mcrcon save-all stop
...

/opt/minecraft/.env:

MCRCON_PORT="25575"
MCRCON_PASS="password"

It should work. Does it work?

sugoidogo commented 3 years ago

No, that's why I'm asking about it.

Hagb commented 3 years ago

Could you paste your entire unit file and output of sudo systemctl status NAME_OF_THE_UNIT after you try to start the unit?

sugoidogo commented 3 years ago

Unfortunately my server just had a catastrophic failure, so it's gonna take me a while to get back to the point I can provide that. Will update when I can.

Tiiffi commented 2 years ago

Closing this issue.

Please open new one if issue persists.