TiddlyWiki
FreeBSD TiddlyWiki rc.d script
After manually starting a TiddlyWiki node.js server in a tmux environment for many years at each reboot of my system, I decided it was finally time to create a fancy rc.d for this. TiddlyWiki can be installed using npm install -g tiddlywiki
.
The rc.d script
The script should be placed in /usr/local/etc/rc.d
.
#!/bin/sh
# PROVIDE: tiddlywiki
# REQUIRE: LOGIN
# KEYWORD: shutdown
. /etc/rc.subr
load_rc_config $name
: ${tiddlywiki_enable:=no}
: ${tiddlywiki_user:="www"}
: ${tiddlywiki_group:="www"}
: ${tiddlywiki_port:="8080"}
name="tiddlywiki"
desc="TiddlyWiki server"
rcvar="tiddlywiki_enable"
command="/usr/local/bin/${name}"
procname="node"
pidfile="/var/run/${name}.pid"
command_args="${tiddlywiki_dir} --listen port=${tiddlywiki_port}"
start_precmd="tiddlywiki_precmd"
start_cmd="daemon -u ${tiddlywiki_user} -p ${pidfile} -f \
${command} ${command_args} ${tiddlywiki_flags}"
PATH="${PATH}:/usr/local/bin" # Otherwise node not found
tiddlywiki_precmd()
{
if [ ! -d ${tiddlywiki_dir} ]; then
info "TiddlyWiki dir does not exist. Creating one ..."
if ! mkdir -p ${tiddlywiki_dir}; then
err 1 "Failed to create TiddlyWiki dir."
fi
chown ${tiddlywiki_user}:${tiddlywiki_group} ${tiddlywiki_dir}
fi
if [ ! -f ${tiddlywiki_dir}/tiddlywiki.info ]; then
info "No tiddlywiki.info found. Creating one ..."
su -m ${tiddlywiki_user} -c "${command} ${tiddlywiki_dir} --init server"
fi
}
run_rc_command "$1"
The procname
variable is defined here, to aid the check_pidfile
to find the correct process. If procname
is not defined it defaults to command
. To give an impression, this is how the process look like in the ps
output: