* [gentoo-user] Writing Gentoo initscript question
@ 2011-03-05 22:47 Jake Moe
2011-03-05 23:31 ` Florian Philipp
0 siblings, 1 reply; 6+ messages in thread
From: Jake Moe @ 2011-03-05 22:47 UTC (permalink / raw
To: gentoo-user
I'm currently trying to write a simple initscript to run
minecraft-server on one of my boxes. I've looked at the ebuild provided
via java-overlay, but it turns out it uses baselayout 2, and I'm not
ready to go down that upgrade path on this particular box just yet.
So far, I've managed to get a simple start() function written, which
kinda-sorta "works"; it will start the server, but there are two problems:
1) The "server" was written to stay interactive on a console, so you can
manage it from there. As such, the process never exits, so the
initscript gets stuck on "starting"
2) There is nowhere in the server config file to specify where it writes
it's data files. So when I run this from my initscript, it seems to
default to the root directory, and I can't figure out how to tell it to
use something else as a working directory.
So far, I've got this:
depend() {
need bootmisc localmount net
}
start() {
einfo "Starting Minecraft Server"
cd /usr/local/games/minecraft-server
start-stop-daemon --start --make-pidfile --pidfile
/var/run/minecraft-server.pid \
--exec /usr/bin/java -- -Xmx1024M -Xms1024M -jar
/usr/local/games/minecraft-server/minecraft_server.jar nogui
eend $?
}
Do any of the experts here know a way out of my dilemma?
Jake Moe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-user] Writing Gentoo initscript question
2011-03-05 22:47 [gentoo-user] Writing Gentoo initscript question Jake Moe
@ 2011-03-05 23:31 ` Florian Philipp
2011-03-06 1:25 ` Jake Moe
0 siblings, 1 reply; 6+ messages in thread
From: Florian Philipp @ 2011-03-05 23:31 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 1836 bytes --]
Am 05.03.2011 23:47, schrieb Jake Moe:
> I'm currently trying to write a simple initscript to run
> minecraft-server on one of my boxes. I've looked at the ebuild provided
> via java-overlay, but it turns out it uses baselayout 2, and I'm not
> ready to go down that upgrade path on this particular box just yet.
>
> So far, I've managed to get a simple start() function written, which
> kinda-sorta "works"; it will start the server, but there are two problems:
>
> 1) The "server" was written to stay interactive on a console, so you can
> manage it from there. As such, the process never exits, so the
> initscript gets stuck on "starting"
> 2) There is nowhere in the server config file to specify where it writes
> it's data files. So when I run this from my initscript, it seems to
> default to the root directory, and I can't figure out how to tell it to
> use something else as a working directory.
>
> So far, I've got this:
>
> depend() {
> need bootmisc localmount net
> }
>
> start() {
> einfo "Starting Minecraft Server"
> cd /usr/local/games/minecraft-server
> start-stop-daemon --start --make-pidfile --pidfile
> /var/run/minecraft-server.pid \
> --exec /usr/bin/java -- -Xmx1024M -Xms1024M -jar
> /usr/local/games/minecraft-server/minecraft_server.jar nogui
> eend $?
> }
>
> Do any of the experts here know a way out of my dilemma?
>
> Jake Moe
>
You already know start-stop-daemon, good. Parameter --background will
force the program to detach. That solves your first problem.
--chdir should solve your second problem. You should also consider
--user and --group to drop root privileges. It also sets $HOME in case
the server does not write to the working directory but the home directory.
Hope this helps,
Florian Philipp
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-user] Writing Gentoo initscript question
2011-03-05 23:31 ` Florian Philipp
@ 2011-03-06 1:25 ` Jake Moe
2011-03-06 6:48 ` Joost Roeleveld
2011-03-06 10:57 ` Florian Philipp
0 siblings, 2 replies; 6+ messages in thread
From: Jake Moe @ 2011-03-06 1:25 UTC (permalink / raw
To: gentoo-user
On 03/06/11 09:31, Florian Philipp wrote:
> Am 05.03.2011 23:47, schrieb Jake Moe:
>> I'm currently trying to write a simple initscript to run
>> minecraft-server on one of my boxes. I've looked at the ebuild provided
>> via java-overlay, but it turns out it uses baselayout 2, and I'm not
>> ready to go down that upgrade path on this particular box just yet.
>>
>> So far, I've managed to get a simple start() function written, which
>> kinda-sorta "works"; it will start the server, but there are two problems:
>>
>> 1) The "server" was written to stay interactive on a console, so you can
>> manage it from there. As such, the process never exits, so the
>> initscript gets stuck on "starting"
>> 2) There is nowhere in the server config file to specify where it writes
>> it's data files. So when I run this from my initscript, it seems to
>> default to the root directory, and I can't figure out how to tell it to
>> use something else as a working directory.
>>
>> So far, I've got this:
>>
>> depend() {
>> need bootmisc localmount net
>> }
>>
>> start() {
>> einfo "Starting Minecraft Server"
>> cd /usr/local/games/minecraft-server
>> start-stop-daemon --start --make-pidfile --pidfile
>> /var/run/minecraft-server.pid \
>> --exec /usr/bin/java -- -Xmx1024M -Xms1024M -jar
>> /usr/local/games/minecraft-server/minecraft_server.jar nogui
>> eend $?
>> }
>>
>> Do any of the experts here know a way out of my dilemma?
>>
>> Jake Moe
>>
>
> You already know start-stop-daemon, good. Parameter --background will
> force the program to detach. That solves your first problem.
>
> --chdir should solve your second problem. You should also consider
> --user and --group to drop root privileges. It also sets $HOME in case
> the server does not write to the working directory but the home directory.
>
> Hope this helps,
> Florian Philipp
>
I've tried "--background", but then it just fails. Adding "--verbose"
as well gives the following:
jmoe@aus8617 /etc/init.d $ sudo /etc/init.d/minecraft-server start
* Starting Minecraft Server
Starting /usr/bin/java...
Detaching to start /usr/bin/java...done. [ !! ]
Not the most helpful of messages.
For the second, of what is "--chdir" an argument? If I read the man
page for start-stop-daemon, it had "--chroot" and "--chuid", but no
"--chdir". I assume that "--chuid" can be used for changing the
user:group of the resulting process, but did you mean chroot instead of
chdir, or does that go with another command?
Also, when I say "the root directory", I don't mean root's home
directory (/root), I mean the root (/) directory. So I wind up with
config files in the root of my filesystem. Not good.
Jake Moe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-user] Writing Gentoo initscript question
2011-03-06 1:25 ` Jake Moe
@ 2011-03-06 6:48 ` Joost Roeleveld
2011-03-06 7:37 ` Jake Moe
2011-03-06 10:57 ` Florian Philipp
1 sibling, 1 reply; 6+ messages in thread
From: Joost Roeleveld @ 2011-03-06 6:48 UTC (permalink / raw
To: gentoo-user
On Sunday 06 March 2011 11:25:47 Jake Moe wrote:
> On 03/06/11 09:31, Florian Philipp wrote:
> > Am 05.03.2011 23:47, schrieb Jake Moe:
> >> I'm currently trying to write a simple initscript to run
> >> minecraft-server on one of my boxes. I've looked at the ebuild
> >> provided
> >> via java-overlay, but it turns out it uses baselayout 2, and I'm not
> >> ready to go down that upgrade path on this particular box just yet.
> >>
> >> So far, I've managed to get a simple start() function written, which
> >> kinda-sorta "works"; it will start the server, but there are two
> >> problems:
> >>
> >> 1) The "server" was written to stay interactive on a console, so you
> >> can
> >> manage it from there. As such, the process never exits, so the
> >> initscript gets stuck on "starting"
> >> 2) There is nowhere in the server config file to specify where it
> >> writes
> >> it's data files. So when I run this from my initscript, it seems to
> >> default to the root directory, and I can't figure out how to tell it
> >> to
> >> use something else as a working directory.
> >>
> >> So far, I've got this:
> >>
> >> depend() {
> >>
> >> need bootmisc localmount net
> >>
> >> }
> >>
> >> start() {
> >>
> >> einfo "Starting Minecraft Server"
> >> cd /usr/local/games/minecraft-server
> >> start-stop-daemon --start --make-pidfile --pidfile
> >>
> >> /var/run/minecraft-server.pid \
> >>
> >> --exec /usr/bin/java --
> >> -Xmx1024M -Xms1024M -jar
> >>
> >> /usr/local/games/minecraft-server/minecraft_server.jar nogui
> >>
> >> eend $?
> >>
> >> }
> >>
> >> Do any of the experts here know a way out of my dilemma?
> >>
> >> Jake Moe
> >
> > You already know start-stop-daemon, good. Parameter --background will
> > force the program to detach. That solves your first problem.
> >
> > --chdir should solve your second problem. You should also consider
> > --user and --group to drop root privileges. It also sets $HOME in case
> > the server does not write to the working directory but the home
> > directory.
> >
> > Hope this helps,
> > Florian Philipp
>
> I've tried "--background", but then it just fails. Adding "--verbose"
> as well gives the following:
>
> jmoe@aus8617 /etc/init.d $ sudo /etc/init.d/minecraft-server start
> * Starting Minecraft Server
> Starting /usr/bin/java...
> Detaching to start /usr/bin/java...done. [ !! ]
>
> Not the most helpful of messages.
>
> For the second, of what is "--chdir" an argument? If I read the man
> page for start-stop-daemon, it had "--chroot" and "--chuid", but no
> "--chdir". I assume that "--chuid" can be used for changing the
> user:group of the resulting process, but did you mean chroot instead of
> chdir, or does that go with another command?
>
> Also, when I say "the root directory", I don't mean root's home
> directory (/root), I mean the root (/) directory. So I wind up with
> config files in the root of my filesystem. Not good.
>
> Jake Moe
Not sure if it's the "recommended" way, but how about using "nohup"?
Eg:
start-stop-daemon --start --make-pidfile --pidfile
/var/run/minecraft-server.pid \
--exec nohup /usr/bin/java -- -Xmx1024M -Xms1024M -jar
Might be that it fails because it looses the stdout/stderr?
--
Joost
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-user] Writing Gentoo initscript question
2011-03-06 6:48 ` Joost Roeleveld
@ 2011-03-06 7:37 ` Jake Moe
0 siblings, 0 replies; 6+ messages in thread
From: Jake Moe @ 2011-03-06 7:37 UTC (permalink / raw
To: gentoo-user
On 03/06/11 16:48, Joost Roeleveld wrote:
> On Sunday 06 March 2011 11:25:47 Jake Moe wrote:
>> On 03/06/11 09:31, Florian Philipp wrote:
>>> Am 05.03.2011 23:47, schrieb Jake Moe:
>>>> I'm currently trying to write a simple initscript to run
>>>> minecraft-server on one of my boxes. I've looked at the ebuild
>>>> provided
>>>> via java-overlay, but it turns out it uses baselayout 2, and I'm not
>>>> ready to go down that upgrade path on this particular box just yet.
>>>>
>>>> So far, I've managed to get a simple start() function written, which
>>>> kinda-sorta "works"; it will start the server, but there are two
>>>> problems:
>>>>
>>>> 1) The "server" was written to stay interactive on a console, so you
>>>> can
>>>> manage it from there. As such, the process never exits, so the
>>>> initscript gets stuck on "starting"
>>>> 2) There is nowhere in the server config file to specify where it
>>>> writes
>>>> it's data files. So when I run this from my initscript, it seems to
>>>> default to the root directory, and I can't figure out how to tell it
>>>> to
>>>> use something else as a working directory.
>>>>
>>>> So far, I've got this:
>>>>
>>>> depend() {
>>>>
>>>> need bootmisc localmount net
>>>>
>>>> }
>>>>
>>>> start() {
>>>>
>>>> einfo "Starting Minecraft Server"
>>>> cd /usr/local/games/minecraft-server
>>>> start-stop-daemon --start --make-pidfile --pidfile
>>>>
>>>> /var/run/minecraft-server.pid \
>>>>
>>>> --exec /usr/bin/java --
>>>> -Xmx1024M -Xms1024M -jar
>>>>
>>>> /usr/local/games/minecraft-server/minecraft_server.jar nogui
>>>>
>>>> eend $?
>>>>
>>>> }
>>>>
>>>> Do any of the experts here know a way out of my dilemma?
>>>>
>>>> Jake Moe
>>> You already know start-stop-daemon, good. Parameter --background will
>>> force the program to detach. That solves your first problem.
>>>
>>> --chdir should solve your second problem. You should also consider
>>> --user and --group to drop root privileges. It also sets $HOME in case
>>> the server does not write to the working directory but the home
>>> directory.
>>>
>>> Hope this helps,
>>> Florian Philipp
>> I've tried "--background", but then it just fails. Adding "--verbose"
>> as well gives the following:
>>
>> jmoe@aus8617 /etc/init.d $ sudo /etc/init.d/minecraft-server start
>> * Starting Minecraft Server
>> Starting /usr/bin/java...
>> Detaching to start /usr/bin/java...done. [ !! ]
>>
>> Not the most helpful of messages.
>>
>> For the second, of what is "--chdir" an argument? If I read the man
>> page for start-stop-daemon, it had "--chroot" and "--chuid", but no
>> "--chdir". I assume that "--chuid" can be used for changing the
>> user:group of the resulting process, but did you mean chroot instead of
>> chdir, or does that go with another command?
>>
>> Also, when I say "the root directory", I don't mean root's home
>> directory (/root), I mean the root (/) directory. So I wind up with
>> config files in the root of my filesystem. Not good.
>>
>> Jake Moe
> Not sure if it's the "recommended" way, but how about using "nohup"?
> Eg:
> start-stop-daemon --start --make-pidfile --pidfile
> /var/run/minecraft-server.pid \
> --exec nohup /usr/bin/java -- -Xmx1024M -Xms1024M -jar
>
> Might be that it fails because it looses the stdout/stderr?
>
> --
> Joost
>
Tried both
--background --exec /usr/bin/nohup /usr/bin/java -- -Xmx1024M...
and
--background --exec /usr/bin/nohup -- /usr/bin/java -Xmx1024M ...
Both output:
jmoe@aus8617 /etc/init.d $ sudo ./minecraft-server start
* Caching service dependencies
...
[ ok ]
* Starting Minecraft Server
Starting /usr/bin/nohup...
Detaching to start
/usr/bin/nohup...done.
[ !! ]
If I leave off the --background, it starts, but never goes back to the
console:
jmoe@aus8617 /etc/init.d $ sudo ./minecraft-server start
* Caching service dependencies
...
[ ok ]
* Starting Minecraft Server
Starting /usr/bin/nohup...
/usr/bin/nohup: ignoring input and appending output to `nohup.out'
It's running, because I can connect to it via my client, but I don't get
control back.
The java-overlay way was to run it using tmux, then connect back to it
when you wanted to use the server console. The problem was that it used
"ewaitfile" in the initscript, and that's not in BL1. Maybe I need to
investigate tmux further and see if I can accomplish the same thing in BL1.
Jake Moe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-user] Writing Gentoo initscript question
2011-03-06 1:25 ` Jake Moe
2011-03-06 6:48 ` Joost Roeleveld
@ 2011-03-06 10:57 ` Florian Philipp
1 sibling, 0 replies; 6+ messages in thread
From: Florian Philipp @ 2011-03-06 10:57 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 3506 bytes --]
Am 06.03.2011 02:25, schrieb Jake Moe:
> On 03/06/11 09:31, Florian Philipp wrote:
>> Am 05.03.2011 23:47, schrieb Jake Moe:
>>> I'm currently trying to write a simple initscript to run
>>> minecraft-server on one of my boxes. I've looked at the ebuild provided
>>> via java-overlay, but it turns out it uses baselayout 2, and I'm not
>>> ready to go down that upgrade path on this particular box just yet.
>>>
>>> So far, I've managed to get a simple start() function written, which
>>> kinda-sorta "works"; it will start the server, but there are two problems:
>>>
>>> 1) The "server" was written to stay interactive on a console, so you can
>>> manage it from there. As such, the process never exits, so the
>>> initscript gets stuck on "starting"
>>> 2) There is nowhere in the server config file to specify where it writes
>>> it's data files. So when I run this from my initscript, it seems to
>>> default to the root directory, and I can't figure out how to tell it to
>>> use something else as a working directory.
>>>
>>> So far, I've got this:
>>>
>>> depend() {
>>> need bootmisc localmount net
>>> }
>>>
>>> start() {
>>> einfo "Starting Minecraft Server"
>>> cd /usr/local/games/minecraft-server
>>> start-stop-daemon --start --make-pidfile --pidfile
>>> /var/run/minecraft-server.pid \
>>> --exec /usr/bin/java -- -Xmx1024M -Xms1024M -jar
>>> /usr/local/games/minecraft-server/minecraft_server.jar nogui
>>> eend $?
>>> }
>>>
>>> Do any of the experts here know a way out of my dilemma?
>>>
>>> Jake Moe
>>>
>>
>> You already know start-stop-daemon, good. Parameter --background will
>> force the program to detach. That solves your first problem.
>>
>> --chdir should solve your second problem. You should also consider
>> --user and --group to drop root privileges. It also sets $HOME in case
>> the server does not write to the working directory but the home directory.
>>
>> Hope this helps,
>> Florian Philipp
>>
> I've tried "--background", but then it just fails. Adding "--verbose"
> as well gives the following:
>
> jmoe@aus8617 /etc/init.d $ sudo /etc/init.d/minecraft-server start
> * Starting Minecraft Server
> Starting /usr/bin/java...
> Detaching to start /usr/bin/java...done. [ !! ]
>
> Not the most helpful of messages.
>
Hmm, no clue what goes wrong. Joost already suggested it has something
to do with stdout and stderr. You can redirect them with -1 and -2 but I
don't think this solves your problem.
Maybe you should take a look at dev-java/java-service-wrapper. I've
never used it, though.
> For the second, of what is "--chdir" an argument? If I read the man
> page for start-stop-daemon, it had "--chroot" and "--chuid", but no
> "--chdir". I assume that "--chuid" can be used for changing the
> user:group of the resulting process, but did you mean chroot instead of
> chdir, or does that go with another command?
>
In my man-page there is definitely a --chdir option. But I'm using
openrc so I guess it was introduced in baselayout-2. As a work-around,
you can wrap your daemon into a shell script that at first uses cd to
change the directory.
> Also, when I say "the root directory", I don't mean root's home
> directory (/root), I mean the root (/) directory. So I wind up with
> config files in the root of my filesystem. Not good.
>
Well in that case it really seems to be the working directory, not the
home directory.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-03-06 11:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-05 22:47 [gentoo-user] Writing Gentoo initscript question Jake Moe
2011-03-05 23:31 ` Florian Philipp
2011-03-06 1:25 ` Jake Moe
2011-03-06 6:48 ` Joost Roeleveld
2011-03-06 7:37 ` Jake Moe
2011-03-06 10:57 ` Florian Philipp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox