Gentoo Archives: gentoo-user

From: Jake Moe <jakesaddress@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Writing Gentoo initscript question
Date: Sun, 06 Mar 2011 07:38:57
Message-Id: 4D7339B5.8080403@gmail.com
In Reply to: Re: [gentoo-user] Writing Gentoo initscript question by Joost Roeleveld
1 On 03/06/11 16:48, Joost Roeleveld wrote:
2 > On Sunday 06 March 2011 11:25:47 Jake Moe wrote:
3 >> On 03/06/11 09:31, Florian Philipp wrote:
4 >>> Am 05.03.2011 23:47, schrieb Jake Moe:
5 >>>> I'm currently trying to write a simple initscript to run
6 >>>> minecraft-server on one of my boxes. I've looked at the ebuild
7 >>>> provided
8 >>>> via java-overlay, but it turns out it uses baselayout 2, and I'm not
9 >>>> ready to go down that upgrade path on this particular box just yet.
10 >>>>
11 >>>> So far, I've managed to get a simple start() function written, which
12 >>>> kinda-sorta "works"; it will start the server, but there are two
13 >>>> problems:
14 >>>>
15 >>>> 1) The "server" was written to stay interactive on a console, so you
16 >>>> can
17 >>>> manage it from there. As such, the process never exits, so the
18 >>>> initscript gets stuck on "starting"
19 >>>> 2) There is nowhere in the server config file to specify where it
20 >>>> writes
21 >>>> it's data files. So when I run this from my initscript, it seems to
22 >>>> default to the root directory, and I can't figure out how to tell it
23 >>>> to
24 >>>> use something else as a working directory.
25 >>>>
26 >>>> So far, I've got this:
27 >>>>
28 >>>> depend() {
29 >>>>
30 >>>> need bootmisc localmount net
31 >>>>
32 >>>> }
33 >>>>
34 >>>> start() {
35 >>>>
36 >>>> einfo "Starting Minecraft Server"
37 >>>> cd /usr/local/games/minecraft-server
38 >>>> start-stop-daemon --start --make-pidfile --pidfile
39 >>>>
40 >>>> /var/run/minecraft-server.pid \
41 >>>>
42 >>>> --exec /usr/bin/java --
43 >>>> -Xmx1024M -Xms1024M -jar
44 >>>>
45 >>>> /usr/local/games/minecraft-server/minecraft_server.jar nogui
46 >>>>
47 >>>> eend $?
48 >>>>
49 >>>> }
50 >>>>
51 >>>> Do any of the experts here know a way out of my dilemma?
52 >>>>
53 >>>> Jake Moe
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 >> I've tried "--background", but then it just fails. Adding "--verbose"
65 >> as well gives the following:
66 >>
67 >> jmoe@aus8617 /etc/init.d $ sudo /etc/init.d/minecraft-server start
68 >> * Starting Minecraft Server
69 >> Starting /usr/bin/java...
70 >> Detaching to start /usr/bin/java...done. [ !! ]
71 >>
72 >> Not the most helpful of messages.
73 >>
74 >> For the second, of what is "--chdir" an argument? If I read the man
75 >> page for start-stop-daemon, it had "--chroot" and "--chuid", but no
76 >> "--chdir". I assume that "--chuid" can be used for changing the
77 >> user:group of the resulting process, but did you mean chroot instead of
78 >> chdir, or does that go with another command?
79 >>
80 >> Also, when I say "the root directory", I don't mean root's home
81 >> directory (/root), I mean the root (/) directory. So I wind up with
82 >> config files in the root of my filesystem. Not good.
83 >>
84 >> Jake Moe
85 > Not sure if it's the "recommended" way, but how about using "nohup"?
86 > Eg:
87 > start-stop-daemon --start --make-pidfile --pidfile
88 > /var/run/minecraft-server.pid \
89 > --exec nohup /usr/bin/java -- -Xmx1024M -Xms1024M -jar
90 >
91 > Might be that it fails because it looses the stdout/stderr?
92 >
93 > --
94 > Joost
95 >
96 Tried both
97 --background --exec /usr/bin/nohup /usr/bin/java -- -Xmx1024M...
98 and
99 --background --exec /usr/bin/nohup -- /usr/bin/java -Xmx1024M ...
100
101 Both output:
102
103 jmoe@aus8617 /etc/init.d $ sudo ./minecraft-server start
104 * Caching service dependencies
105 ...
106 [ ok ]
107 * Starting Minecraft Server
108 Starting /usr/bin/nohup...
109 Detaching to start
110 /usr/bin/nohup...done.
111 [ !! ]
112
113 If I leave off the --background, it starts, but never goes back to the
114 console:
115
116 jmoe@aus8617 /etc/init.d $ sudo ./minecraft-server start
117 * Caching service dependencies
118 ...
119 [ ok ]
120 * Starting Minecraft Server
121 Starting /usr/bin/nohup...
122 /usr/bin/nohup: ignoring input and appending output to `nohup.out'
123
124 It's running, because I can connect to it via my client, but I don't get
125 control back.
126
127 The java-overlay way was to run it using tmux, then connect back to it
128 when you wanted to use the server console. The problem was that it used
129 "ewaitfile" in the initscript, and that's not in BL1. Maybe I need to
130 investigate tmux further and see if I can accomplish the same thing in BL1.
131
132 Jake Moe