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:
#!/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
doas rc-service mongodb start --verbose
it return:
* 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?
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 ?
command_user="${MONGOD_USER}:${MONGOD_GROUP}"
Why not just cut out the middle man and
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)"
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
doas rc-service mongodb stop --verbose
it returned
* WARNING: mongodb is already stopped
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.