Artix Linux Forum

Init systems => OpenRC => Topic started by: theeast on 05 May 2024, 09:43:56

Title: Init script for MongoDB
Post by: theeast on 05 May 2024, 09:43:56
I'm trying to write a openrc init script for MongoDB following this guide (https://github.com/OpenRC/openrc/blob/master/service-script-guide.md). 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?
Title: Re: Init script for MongoDB
Post by: gripped on 05 May 2024, 20:58:31
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)"
Title: Re: Init script for MongoDB
Post by: theeast on 06 May 2024, 05:00:01
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.
Title: Re: Init script for MongoDB
Post by: lq on 06 May 2024, 10:48:18
So the service is not running at all.

Because you probably need not only *.initd (https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-db/mongodb/files/mongodb.initd-r3) but also *.confd (https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-db/mongodb/files/mongodb.conf-r3) script.