Gentoo Archives: gentoo-user

From: Florian Philipp <lists@×××××××××××.net>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Writing Gentoo initscript question
Date: Sun, 06 Mar 2011 11:00:13
Message-Id: 4D73688C.2090409@binarywings.net
In Reply to: Re: [gentoo-user] Writing Gentoo initscript question by Jake Moe
1 Am 06.03.2011 02:25, schrieb Jake Moe:
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 provided
6 >>> via java-overlay, but it turns out it uses baselayout 2, and I'm not
7 >>> ready to go down that upgrade path on this particular box just yet.
8 >>>
9 >>> So far, I've managed to get a simple start() function written, which
10 >>> kinda-sorta "works"; it will start the server, but there are two problems:
11 >>>
12 >>> 1) The "server" was written to stay interactive on a console, so you can
13 >>> manage it from there. As such, the process never exits, so the
14 >>> initscript gets stuck on "starting"
15 >>> 2) There is nowhere in the server config file to specify where it writes
16 >>> it's data files. So when I run this from my initscript, it seems to
17 >>> default to the root directory, and I can't figure out how to tell it to
18 >>> use something else as a working directory.
19 >>>
20 >>> So far, I've got this:
21 >>>
22 >>> depend() {
23 >>> need bootmisc localmount net
24 >>> }
25 >>>
26 >>> start() {
27 >>> einfo "Starting Minecraft Server"
28 >>> cd /usr/local/games/minecraft-server
29 >>> start-stop-daemon --start --make-pidfile --pidfile
30 >>> /var/run/minecraft-server.pid \
31 >>> --exec /usr/bin/java -- -Xmx1024M -Xms1024M -jar
32 >>> /usr/local/games/minecraft-server/minecraft_server.jar nogui
33 >>> eend $?
34 >>> }
35 >>>
36 >>> Do any of the experts here know a way out of my dilemma?
37 >>>
38 >>> Jake Moe
39 >>>
40 >>
41 >> You already know start-stop-daemon, good. Parameter --background will
42 >> force the program to detach. That solves your first problem.
43 >>
44 >> --chdir should solve your second problem. You should also consider
45 >> --user and --group to drop root privileges. It also sets $HOME in case
46 >> the server does not write to the working directory but the home directory.
47 >>
48 >> Hope this helps,
49 >> Florian Philipp
50 >>
51 > I've tried "--background", but then it just fails. Adding "--verbose"
52 > as well gives the following:
53 >
54 > jmoe@aus8617 /etc/init.d $ sudo /etc/init.d/minecraft-server start
55 > * Starting Minecraft Server
56 > Starting /usr/bin/java...
57 > Detaching to start /usr/bin/java...done. [ !! ]
58 >
59 > Not the most helpful of messages.
60 >
61
62 Hmm, no clue what goes wrong. Joost already suggested it has something
63 to do with stdout and stderr. You can redirect them with -1 and -2 but I
64 don't think this solves your problem.
65
66 Maybe you should take a look at dev-java/java-service-wrapper. I've
67 never used it, though.
68
69 > For the second, of what is "--chdir" an argument? If I read the man
70 > page for start-stop-daemon, it had "--chroot" and "--chuid", but no
71 > "--chdir". I assume that "--chuid" can be used for changing the
72 > user:group of the resulting process, but did you mean chroot instead of
73 > chdir, or does that go with another command?
74 >
75
76 In my man-page there is definitely a --chdir option. But I'm using
77 openrc so I guess it was introduced in baselayout-2. As a work-around,
78 you can wrap your daemon into a shell script that at first uses cd to
79 change the directory.
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
86 Well in that case it really seems to be the working directory, not the
87 home directory.

Attachments

File name MIME type
signature.asc application/pgp-signature