Skip to main content
Topic: Init script for MongoDB (Read 490 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Init script for MongoDB

I'm trying to write a openrc init script for MongoDB following this guide. Here's what I got done so far:

Code: [Select]
#!/sbin/openrc-run

MONGOD_USER="${MONGOD_USER:-mongodb}"
MONGOD_GROUP="${MONGOD_GROUP:-mongodb}"
MONGOD_CONFIG="${MONGOD_CONFIG:-/etc/mongodb.conf}"
MONGOD_LOGFILE="${MONGOD_LOGFILE:-/var/log/mongodb/mongod.log}"

description="MongoDB service"
pidfile="/run/mongodb.pid"
supervisor=supervise-daemon
command="/usr/bin/mongod"
command_args="--config ${MONGOD_CONFIG}"
command_user="${MONGOD_USER}:${MONGOD_GROUP}"
output_log="$MONGOD_LOGFILE"
error_log="$output_log"

depend() {
need net
after firewall
}

The script doesn't work though. When I start it with
Code: [Select]
doas rc-service mongodb start --verbose
it return:

Code: [Select]
 * Executing: /usr/lib/openrc/sh/openrc-run.sh /usr/lib/openrc/sh/openrc-run.sh /etc/init.d/mongodb start
 * Starting mongodb ... * supervise-daemon: fopen `/run/mongodb.pid': No such file or directory
 * Detaching to start `/usr/bin/mongod'
 [ ok ]

But I can't find the pid file for the service, any suggestions?

Re: Init script for MongoDB

Reply #1
Code: [Select]
MONGOD_USER="mongodb"
MONGOD_GROUP="mongodb"
MONGOD_CONFIG="/etc/mongodb.conf"
MONGOD_LOGFILE="/var/log/mongodb/mongod.log"

The way you had written that looks very strange to me.

And some of the rest of is probably over complicated ?
Code: [Select]
command_user="${MONGOD_USER}:${MONGOD_GROUP}"
Why not just cut out the middle man and
Code: [Select]
command_user="mongodb:mongodb"

Disclaimer:
I have no idea what mongodb is or does (Though I'd hazard a guess it's a database)
I'm just pointing out the bits that look weird to me at a first glance. Writing openrc services befuddles me as well at times. To the extent that I'm left thinking "It's not me, it's you(openrc)"

Re: Init script for MongoDB

Reply #2
The way you had written that looks very strange to me.

I was mostly copying ideas from the syncthing init script on my machine. The openrc way of scripting has changed a lot since the last time I wrote one so I had to learn from scratch. But I guess it's not too complicated and the main problem is just with the pid file.

Also update when I exec
Code: [Select]
doas rc-service mongodb stop --verbose
it returned

Code: [Select]
* WARNING: mongodb is already stopped

So the service is not running at all.

 

Re: Init script for MongoDB

Reply #3
So the service is not running at all.

Because you probably need not only *.initd but also *.confd script.
"Wer alles kann, macht nichts richtig"

Artix USE="runit openrc slim openbox lxde gtk2 qt4 qt5 qt6 conky
-gtk3 -gtk4 -adwaita{cursors,themes,icons} -gnome3 -kde -plasma -wayland "