I've formulated an rc script for meshcentral, and have a question.
Why would this work
But this wont
The only thing that changed is the user variable. When I use the first script, things just work.
But when I try to use the second one, daemon start complaining "could not set user environment" or "initgroup meshcentral failed"
The user was created with
Or would it be best not to run it as a daemon, and use “su -m ${meshcentral_user}” instead?
Why would this work
Code:
#!/bin/sh
#
# MeshCentral FreeBSD Service Script
#
#
# PROVIDE: meshcentral
# REQUIRE: NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name=meshcentral
desc="MeshCentral Computer Management"
rcvar=meshcentral_enable
load_rc_config $name
: ${meshcentral_enable:="NO"}
: ${meshcentral_args:=""}
: ${meshcentral_chdir:="/usr/local/meshcentral"}
: ${meshcentral_rundir:="/var/run/${name}"}
: ${meshcentral_logdir:="/var/log/${name}"}
: ${meshcentral_pidfile:="${meshcentral_rundir}/${name}.pid"}
: ${meshcentral_logfile:="${meshcentral_logdir}/${name}.log"}
user="meshcentral"
group="meshcentral"
node="/usr/local/bin/node"
command="/usr/sbin/daemon"
command_args="-u ${user} -P ${meshcentral_pidfile} -H -o ${meshcentral_logfile} ${node} node_modules/${name} ${meshcentral_args}"
start_precmd="meshcentral_startprecmd"
meshcentral_startprecmd()
{
if [ ! -d ${meshcentral_rundir} ]; then
install -d -o ${user} -g ${group} ${meshcentral_rundir};
else
chown -R ${user}:${group} ${meshcentral_rundir};
fi
if [ ! -d ${meshcentral_logdir} ]; then
install -d -o ${user} -g ${group} ${meshcentral_logdir};
else
chown -R ${user}:${group} ${meshcentral_logdir};
fi
}
run_rc_command "$1"
But this wont
Code:
#!/bin/sh
#
# MeshCentral FreeBSD Service Script
#
#
# PROVIDE: meshcentral
# REQUIRE: NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name=meshcentral
desc="MeshCentral Computer Management"
rcvar=meshcentral_enable
load_rc_config $name
: ${meshcentral_enable:="NO"}
: ${meshcentral_args:=""}
: ${meshcentral_chdir:="/usr/local/meshcentral"}
: ${meshcentral_rundir:="/var/run/${name}"}
: ${meshcentral_logdir:="/var/log/${name}"}
: ${meshcentral_pidfile:="${meshcentral_rundir}/${name}.pid"}
: ${meshcentral_logfile:="${meshcentral_logdir}/${name}.log"}
: ${meshcentral_group:="meshcentral"}
: ${meshcentral_user:="meshcentral"}
node="/usr/local/bin/node"
command="/usr/sbin/daemon"
command_args="-u ${meshcentral_user} -P ${meshcentral_pidfile} -H -o ${meshcentral_logfile} ${node} node_modules/${name} ${meshcentral_args}"
start_precmd="meshcentral_startprecmd"
meshcentral_startprecmd()
{
if [ ! -d ${meshcentral_rundir} ]; then
install -d -o ${meshcentral_user} -g ${meshcentral_group} ${meshcentral_rundir};
else
chown -R ${meshcentral_user}:${meshcentral_group} ${meshcentral_rundir};
fi
if [ ! -d ${meshcentral_logdir} ]; then
install -d -o ${meshcentral_user} -g ${meshcentral_group} ${meshcentral_logdir};
else
chown -R ${meshcentral_user}:${meshcentral_group} ${meshcentral_logdir};
fi
}
run_rc_command "$1"
The only thing that changed is the user variable. When I use the first script, things just work.
But when I try to use the second one, daemon start complaining "could not set user environment" or "initgroup meshcentral failed"
The user was created with
pw user add meshcentral -c meshcentral -u 6374 -s /usr/sbin/nologin -d /home/meshcentral -m
Or would it be best not to run it as a daemon, and use “su -m ${meshcentral_user}” instead?