Hello everyone,
Today, I set up an Anki syncserver in my Jail. Since the Anki official documentation does not mention how to set it up as a service, I followed the FreeBSD handbook and other users' services as examples to create an rc.d service.
After some testing, it works, but there are a few things I don't understand. I would like to know if this is the correct way to achieve it.
In my Anki syncserver service, the user anki is a nologin shell user. Since they cannot run commands directly, it seems I can only use the precmd method to start the service and use rc_flags inside the precmd (prestart function) to create a PID file.
To avoid everything showing in the terminal, I set the output to /dev/null by
I also don't understand why I have to set
Additionally, to test if the nologin user can run the command without problems, I have to use
Today, I set up an Anki syncserver in my Jail. Since the Anki official documentation does not mention how to set it up as a service, I followed the FreeBSD handbook and other users' services as examples to create an rc.d service.
After some testing, it works, but there are a few things I don't understand. I would like to know if this is the correct way to achieve it.
In my Anki syncserver service, the user anki is a nologin shell user. Since they cannot run commands directly, it seems I can only use the precmd method to start the service and use rc_flags inside the precmd (prestart function) to create a PID file.
To avoid everything showing in the terminal, I set the output to /dev/null by
>> /dev/null 2>&1
, but is this the correct way to do it?I also don't understand why I have to set
${rc_flags}
at the end of the rc_flags
.Additionally, to test if the nologin user can run the command without problems, I have to use
su -m anki -c cmd
. Is there any other method to overcome the nologin shell?
Code:
#!/bin/sh
# $FreeBSD$
#
# PROVIDE: anki
# REQUIRE: LOGIN SERVERS DAEMON resolv
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# anki_enable: Set to YES to enable anki
# Default: NO
# anki_user: The user account used to run the anki daemon.
# This is optional, however do not specifically set this to an
# empty string as this will cause the daemon to run as root.
# Default: anki
# anki_group: The group account used to run the anki daemon.
# This is optional, however do not specifically set this to an
# empty string as this will cause the daemon to run with group wheel.
# Default: anki
# anki_env: The environment variable used to control anki syncserver preperties.
# This is optional.
# For details, please check https://docs.ankiweb.net/sync-server.html
# Default: anki
. /etc/rc.subr
name="anki"
rcvar=${name}_enable
anki_chdir="/usr/local/etc/anki"
load_rc_config $name
USER1="zero:test"
BASE="/usr/local/etc/anki/syncserver"
HOST="127.0.0.1"
: ${anki_enable:="NO"}
: ${anki_user:="anki"}
: ${anki_group:="anki"}
: ${anki_env:="SYNC_USER1=${USER1} SYNC_BASE=${BASE} SYNC_HOST=${HOST}"}
pidfile_child="${anki_chdir}/${name}.pid"
pidfile="${anki_chdir}/${name}_daemon.pid"
command="/usr/sbin/daemoesn"
start_precmd="${name}_prtart"
#procname="python3"
anki_prestart() {
rc_flags="-P ${pidfile} -p ${pidfile_child} /usr/local/bin/anki --syncserver >> /dev/null 2>&1 ${rc_flags}"
# rc_flags="-P ${pidfile} -p ${pidfile_child} /usr/local/bin/anki --syncserver ${rc_flags}"
}
run_rc_command "$1"