Starting server using CLI fails with error


I need to be able to start/stop my servers from a bash script. Stopping servers works, running commands works (stuff) but I can’t start servers.

It gives me this message:

root@minecraft:~# runuser -u minecraft -- /usr/games/minecraft/mineos_console.js -s Hub start
        cmdProc.stdout.on('data', this._outputHandlers.stdout);

TypeError: Cannot read property 'on' of undefined
    at Rsync.execute (/usr/games/minecraft/node_modules/rsync/rsync.js:512:24)
    at /usr/games/minecraft/mineos.js:764:13
    at fn (/usr/games/minecraft/node_modules/async/lib/async.js:746:34)
    at /usr/games/minecraft/node_modules/async/lib/async.js:1213:16
    at /usr/games/minecraft/node_modules/async/lib/async.js:166:37
    at /usr/games/minecraft/node_modules/async/lib/async.js:706:43
    at /usr/games/minecraft/node_modules/async/lib/async.js:167:37
    at Object.async.waterfall (/usr/games/minecraft/node_modules/async/lib/async.js:710:44)
    at (/usr/games/minecraft/mineos.js:749:11)
    at /usr/games/minecraft/mineos.js:809:16

Starting the servers using the WebUI works fine.
Can someone explain what that error means?

rsync seems to be a big part of this error. I’m wondering if your runuser command is starting a process by minecraft that doesn’t load/change the environment so that rsync can be found?

If the webui works, we know it’s available–but if it can’t be run using this method, it could be environmental variable differences.

From the runuser manpage.

       runuser  reads  the  /etc/default/runuser  and /etc/login.defs configuration files.
       The following configuration items are relevant for runuser:

       ENV_PATH (string)
           Defines the PATH environment variable for a regular user.  The default value is

       ENV_ROOTPATH (string)
       ENV_SUPATH (string)
           Defines  the  PATH environment variable for root.  ENV_SUPATH takes precedence.
           The  default  value   is   /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:

       ALWAYS_SET_PATH (boolean)
           If set to yes and --login and --preserve-environment were not specified runuser
           initializes PATH.

       The environment variable PATH may be different on systems where /bin and /sbin  are
       merged into /usr; this variable is also affected by the --login command-line option
       and the PAM system setting (e.g., pam_env(8)).

All that said, it’s perfectly ok to run mineos_console.js as root, because the underlying libraries start the subprocess for Java/Minecraft under the intended users UID & GID, anyway.

1 Like

You are right. Running the command directly as root works:
root@minecraft$ /usr/games/minecraft/mineos_console.js -s Hub start

Running it directly as my minecraft user doesn’t:
minecraft@minecraft$ /usr/games/minecraft/mineos_console.js -s Hub start

I tried to run it as my minecraft user because the only info I could find about how to use the command line was this here and here (which are both totally outdated refering to a python version with completely different commands and so on) and there it is written:

./ should always be run as user mc, under all circumstances. Even when it is unavoidable that the script is called by root, ensure that mc is called with ‘su’ (substitute user), as for crontabs. If any files are modified or created as root, further attempts to access them via the web-ui will fail, as ‘mc’ will not have sufficient permissions. If, for example, the server is started as root, attempts to stop the server will be greeted with an error or blank page, upon failing to write to the lock files.

I ran the top command and it looks like the mineos process is running as root and my minecraft servers as my unprivileged user “minecraft”. I looked at the debian install instruction again and it tells to install everything as root. So I guess it makes sense that the minecraft user maybe didn’t got the rights to use rsync packaged with mineos when the mineos files are owned by root.

Does mineos really require to be installed as root or would it be fine if I create a new unprivileged user “mineos” and chown all mineos files that are now owned by root to that mineos user?

By the way…is it somehow possible to get the player amount of a server by using CLI? Maybe a property I could read using the mineos_console? Or a file I could parse to get this value?
Only other way to get the number of players that comes to my mind would be to use the mineos_console to send a command to that server to count the number of players and write them to the server log. And then somehow parse the logfile to get the player number.
But the mineos webUI is also showing the number of players so I thought it might be easiert to get it directly from mineos.

My final goal is to write a minecraft/bungee plugin for myself that will shutdown a server if it empty for an hour and to be able to start it again from ingame. So I really don’t want that mineos_console to be run as root. Even if that bash script calling the mineos_console is hardcoded without any arguments.