Skip to content

Instantly share code, notes, and snippets.

@gunnarrt
Last active May 30, 2023 12:56
Show Gist options
  • Save gunnarrt/df6831e047024bbff3dd1a7d0b6d24a8 to your computer and use it in GitHub Desktop.
Save gunnarrt/df6831e047024bbff3dd1a7d0b6d24a8 to your computer and use it in GitHub Desktop.
Medusa FreeBSD 13.2, python39
#!/bin/sh
#
# PROVIDE: medusa
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# medusa_enable (bool): Set to NO by default.
# Set it to YES to enable it.
# medusa_user: The user account Medusa daemon runs as what
# you want it to be. It uses 'medusa' user by
# default. Do not sets it as empty or it will run
# as root.
# medusa_group: The group account Medusa daemon runs as what
# you want it to be. It uses 'medusa' group by
# default. Do not sets it as empty or it will run
# as wheel.
# medusa_dir: Directory where Medusa lives.
# Default: /usr/local/medusa
#
# medusa_datadir: Data directory for Medusa (DB, Logs, config)
# Default is same as medusa_dir
# medusa_python_dir: The directory where python is installed.
# Default: /usr/local/bin/python3.7
. /etc/rc.subr
name="medusa"
rcvar=${name}_enable
load_rc_config ${name}
: ${medusa_enable:="NO"}
: ${medusa_user:="medusa"}
: ${medusa_group:="medusa"}
: ${medusa_dir:="/usr/local/medusa"}
: ${medusa_datadir:="${medusa_dir}"}
: ${medusa_python_dir="/usr/local/bin/python3.9"}
pidfile="/var/run/PyMedusa/Medusa.pid"
pidfile_child="/var/run/PyMedusa/Medusa_child.pid"
command="/usr/sbin/daemon"
command_args="-cf -P ${pidfile} -p ${pidfile_child} ${medusa_python_dir} ${medusa_dir}/start.py -q --nolaunch --pidfile /var/run/Pymedusa/child.pid --datadir ${medusa_datadir}"
start_precmd="medusa_prestart"
stop_precmd="medusa_prestop"
stop_postcmd="medusa_poststop"
medusa_prestart() {
if [ -f ${pidfile} ]; then
rm -f ${pidfile}
echo "Removing stale pidfile."
elif [ ! -d ${pidfile%/*} ]; then
install -d -o ${medusa_user} -g ${medusa_group} ${pidfile%/*}
fi
if [ ! -d ${medusa_datadir} ]; then
install -d -o ${medusa_user} -g ${medusa_group} ${medusa_datadir}
fi
}
medusa_prestop() {
if [ -r ${pidfile} ]; then
export _MEDUSAPID=$(check_pidfile ${pidfile} daemon)
fi
}
medusa_poststop() {
_MEDUSA_CHILDREN=$(pgrep -g ${_MEDUSAPID})
echo "Waiting for child processes to stop."
kill -3 ${_MEDUSA_CHILDREN}
wait_for_pids ${_MEDUSA_CHILDREN}
}
run_rc_command "$1"

Create jail: Bastille or other flavor

Install: pkg update && pkg upgrade pkg install nano git-lite python39 py39-pip py39-lxml py39-sqlite3 unrar openssl ffmpeg

#Create a User for Medusa:

$ adduser

Username: medusa Full name: Medusa User Uid (Leave empty for default): Login group [medusa]: Login group is medusa. Invite medusa into other groups? []: Login class [default]: Shell (sh csh tcsh git-shell nologin) [sh]: Home directory [/home/medusa]: Home directory permissions (Leave empty for default): Use password-based authentication? [yes]: no Lock out the account after creation? [no]: no

Install Medusa:

git clone https://github.com/pymedusa/Medusa.git /usr/local/medusa cp /usr/local/medusa/runscripts/init.freebsd /usr/local/etc/rc.d/medusa

chmod 755 /usr/local/etc/rc.d/medusa chown -Rf medusa:medusa /usr/local/medusa chmod u+x /usr/local/etc/rc.d/medusa sysrc "medusa_enable=YES" sysrc "medusa_user=medusa"

nano /usr/local/etc/rc.d/medusa

change line

: ${medusa_python_dir="/usr/local/bin/python3.7"}

to

: ${medusa_python_dir="/usr/local/bin/python3.9"}

service medusa start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment