1 |
On Sunday 06 March 2011 11:25:47 Jake Moe wrote: |
2 |
> On 03/06/11 09:31, Florian Philipp wrote: |
3 |
> > Am 05.03.2011 23:47, schrieb Jake Moe: |
4 |
> >> I'm currently trying to write a simple initscript to run |
5 |
> >> minecraft-server on one of my boxes. I've looked at the ebuild |
6 |
> >> provided |
7 |
> >> via java-overlay, but it turns out it uses baselayout 2, and I'm not |
8 |
> >> ready to go down that upgrade path on this particular box just yet. |
9 |
> >> |
10 |
> >> So far, I've managed to get a simple start() function written, which |
11 |
> >> kinda-sorta "works"; it will start the server, but there are two |
12 |
> >> problems: |
13 |
> >> |
14 |
> >> 1) The "server" was written to stay interactive on a console, so you |
15 |
> >> can |
16 |
> >> manage it from there. As such, the process never exits, so the |
17 |
> >> initscript gets stuck on "starting" |
18 |
> >> 2) There is nowhere in the server config file to specify where it |
19 |
> >> writes |
20 |
> >> it's data files. So when I run this from my initscript, it seems to |
21 |
> >> default to the root directory, and I can't figure out how to tell it |
22 |
> >> to |
23 |
> >> use something else as a working directory. |
24 |
> >> |
25 |
> >> So far, I've got this: |
26 |
> >> |
27 |
> >> depend() { |
28 |
> >> |
29 |
> >> need bootmisc localmount net |
30 |
> >> |
31 |
> >> } |
32 |
> >> |
33 |
> >> start() { |
34 |
> >> |
35 |
> >> einfo "Starting Minecraft Server" |
36 |
> >> cd /usr/local/games/minecraft-server |
37 |
> >> start-stop-daemon --start --make-pidfile --pidfile |
38 |
> >> |
39 |
> >> /var/run/minecraft-server.pid \ |
40 |
> >> |
41 |
> >> --exec /usr/bin/java -- |
42 |
> >> -Xmx1024M -Xms1024M -jar |
43 |
> >> |
44 |
> >> /usr/local/games/minecraft-server/minecraft_server.jar nogui |
45 |
> >> |
46 |
> >> eend $? |
47 |
> >> |
48 |
> >> } |
49 |
> >> |
50 |
> >> Do any of the experts here know a way out of my dilemma? |
51 |
> >> |
52 |
> >> Jake Moe |
53 |
> > |
54 |
> > You already know start-stop-daemon, good. Parameter --background will |
55 |
> > force the program to detach. That solves your first problem. |
56 |
> > |
57 |
> > --chdir should solve your second problem. You should also consider |
58 |
> > --user and --group to drop root privileges. It also sets $HOME in case |
59 |
> > the server does not write to the working directory but the home |
60 |
> > directory. |
61 |
> > |
62 |
> > Hope this helps, |
63 |
> > Florian Philipp |
64 |
> |
65 |
> I've tried "--background", but then it just fails. Adding "--verbose" |
66 |
> as well gives the following: |
67 |
> |
68 |
> jmoe@aus8617 /etc/init.d $ sudo /etc/init.d/minecraft-server start |
69 |
> * Starting Minecraft Server |
70 |
> Starting /usr/bin/java... |
71 |
> Detaching to start /usr/bin/java...done. [ !! ] |
72 |
> |
73 |
> Not the most helpful of messages. |
74 |
> |
75 |
> For the second, of what is "--chdir" an argument? If I read the man |
76 |
> page for start-stop-daemon, it had "--chroot" and "--chuid", but no |
77 |
> "--chdir". I assume that "--chuid" can be used for changing the |
78 |
> user:group of the resulting process, but did you mean chroot instead of |
79 |
> chdir, or does that go with another command? |
80 |
> |
81 |
> Also, when I say "the root directory", I don't mean root's home |
82 |
> directory (/root), I mean the root (/) directory. So I wind up with |
83 |
> config files in the root of my filesystem. Not good. |
84 |
> |
85 |
> Jake Moe |
86 |
|
87 |
Not sure if it's the "recommended" way, but how about using "nohup"? |
88 |
Eg: |
89 |
start-stop-daemon --start --make-pidfile --pidfile |
90 |
/var/run/minecraft-server.pid \ |
91 |
--exec nohup /usr/bin/java -- -Xmx1024M -Xms1024M -jar |
92 |
|
93 |
Might be that it fails because it looses the stdout/stderr? |
94 |
|
95 |
-- |
96 |
Joost |