Skip to content

Instantly share code, notes, and snippets.

@bazadactyl
Created June 15, 2017 02:52
Show Gist options
  • Save bazadactyl/b0fd511303231e4dbf4233c18047f061 to your computer and use it in GitHub Desktop.
Save bazadactyl/b0fd511303231e4dbf4233c18047f061 to your computer and use it in GitHub Desktop.
Lovelace Engine FreeBSD Service Configuration
#!/bin/sh
# PROVIDE: engine
# REQUIRE: DAEMON
# AFTER: LOGIN
# KEYWORD: nojail shutdown
. /etc/rc.subr
# When managing the service using "service engine (start|stop)"
# the PATH doesn't include executables in /usr/local/bin
export PATH=/usr/local/bin:$PATH
# Engine installation directory
engine_dir=/usr/home/freebsd/lovelace-engine/
# Specify the name of the service
name="engine"
rcvar="engine_enable"
# Gunicorn master process PID
pidfile="/var/run/${name}.pid"
# Fail on Engine start-up if these files are missing
required_files="${engine_dir}"
# Gunicorn's master process reloads on SIGHUP
sig_reload="HUP"
# Specify functions to call on service start and stop
start_precmd="${name}_prestart"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
#stop_postcmd="${name}_poststop"
# Use default rc.d behaviour for "reload" and "status"
# and specify custom "setup" command
extra_commands="reload status setup"
# Specify functions to call for custom commands
setup_cmd="${name}_setup"
engine_prestart()
{
# We want to make sure the virtual environment is set up
# Assume that if the python executable exists, we're good to go
if [ ! -e $engine_dir/env/bin/python ]
then
make -C $engine_dir prepare-venv
fi
}
engine_start()
{
make -C $engine_dir start-engine
}
engine_stop()
{
make -C $engine_dir stop-engine
}
#engine_poststop()
#{
# make -C $engine_dir clean
#}
engine_setup()
{
make -C $engine_dir clean
make -C $engine_dir prepare-venv
}
# By default, the Engine should enabled (i.e, start on boot)
load_rc_config $name
: ${engine_enable:="yes"}
# Let rc.d handle the request
run_rc_command "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment