Solved Run Craftbukkit in background from PHP(close to solved)

Discussion in 'Bukkit Help' started by teuneboon, Jan 26, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    teuneboon

    I want to make some kind of management console for my minecraft test server(we're working on mods for our server with a couple of people, so easy restarting does come in handy). To run CraftBukkit in the background before I just used screen. But you can't use screen properly from PHP(since it requires a terminal to be open), and that's why I devised this little script:
    PHP:
    <?php
    $pid 
    system('sh dev-mc/minecraft.sh >out.txt & echo $!');
    file_put_contents('pid.txt'$pid);
    ?>
    and my minecraft.sh:
    Code:
    #!/bin/sh
    BINDIR="$(dirname "$(readlink -fn "$0")")"
    cd "$BINDIR"
    java -Xincgc -Xmx2G -jar craftbukkit.jar
    Which has one kind of huge problem: while it's running craftbukkit is outputting the > character extremely rapidly(almost same effect as if you'd press enter very rapidly). Rapidly enough to bring my cpu usage to > 100%.

    So is there a way to run CraftBukkit from PHP without it outputting all that greater than signs, or should I create a simple plugin that opens a socket or something with which bukkit can restart?

    I run a Ubuntu Server based OS(I modified quite a lot, but it comes closest to Ubuntu Server). With PHP 5.3.

    Thanks for reading(and all the fish(woohoo, made a reference))
     
  2. Offline

    Firelight7300

    What programming languages do you know?
    BTW, why do you need this? ">out.txt" Craftbukkit outputs it's own log.
     
  3. Offline

    teuneboon

    I know a ton of programming languages(Java, PHP, Python, C#(not very useful on linux XD), Javascript, Haskell etc. etc.), C and C++ not very well though.

    And I need the >out.txt because if I don't place that the process just doesn't go to the background, the PHP-script keeps on running, same if I try that command from the commandline(maybe that's the real issue here).
     
  4. Offline

    Pezmantbh

    The reason screen doesn't work through PHP by default is because the way the linux process tree works means that when the parent (php process) is closed, so are all the childeren (screen). To automatically get screen to disown PHP, you can put an & at the end of the screen command :)

    Not specifically what you asked for though.
     
  5. Offline

    Firelight7300

    Try using "break;" even though there's no loop.

    Why can't you just use remote toolkit if you know json?
     
  6. Offline

    teuneboon

    Already knew that yes
    Because I didn't know there was that remote toolkit, I think this solved my problem :) Thanks
     
  7. Offline

    Firelight7300

    Your welcome.
     
Thread Status:
Not open for further replies.

Share This Page