Donate to the B3 fund!

"even a small donation helps!"
Donate with PayPal!
January Donations
MordyT USD25.00

Author Topic: Run B3 as a FreeBSD Daemon  (Read 5939 times)

Offline danlee

  • Newbie
  • *
  • Posts: 2
    • Dan Lee
Run B3 as a FreeBSD Daemon
« on: May 25, 2011, 01:15:28 AM »
After doing a lot of searching and digging, I was finally able to modify and create a start up script for big brother bot for anyone who is running it on FreeBSD.

Credits go to wernerdev

The basic jist of how I have big brother bot setup on my server is as follows.

I have my start up script saved to:
Code: [Select]
# REQUIRE: mysql
# KEYWORD: shutdown
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
# b3_enable (bool):     Set to NO by default.
#                               Set it to YES to enable b3.

. /etc/rc.subr


load_rc_config ${name}

: ${b3_enable:="NO"}
: ${b3_user:="b3"}
: ${b3_dir:="/home/b3/bigbrotherbot"}
: ${b3_chdir:="${b3_dir}"}
: ${b3_pid:="${b3_dir}/"}


command_args="-f -p ${b3_pid} python ${b3_dir}/  -c ${b3_dir}/conf/b3.xml"

# Ensure user is root when running this script
if [ `id -u` != "0" ]; then
echo "Oops, you should be root before running this!"
exit 1

verify_b3_pid() {
# Make sure the pid corresponds to the b3 process
pid=`cat ${b3_pid} 2>/dev/null`
ps -p ${pid} | grep -q "python ${b3_dir}/"
return $?

# Try to stop b3 cleanly
b3_stop() {
echo "Stopping $name"
kill ${pid}
if [ -n "${pid}" ]; then
wait_for_pids ${pid}
echo "Stopped"

b3_status() {
verify_b3_pid && echo "$name is running as ${pid}" || echo "$name is not running"

run_rc_command "$1"
With this script you can stop/start/restart/ and check the status of big brother bot, ie is it running or not.

I have big brother bot installed at /home/b3/bigbrotherbot with an unprivileged user, b3, that runs my big brother bot.

I also created a directory under /var/log/b3 that is owned by b3 as I like to have my logs in one place.  This ensures that the installation directory does not get clogged up with log files.

Other than that its pretty straight forward, hope this helps someone out as it drove me nuts for the past 2 days :)

Offline MordyT

  • Moderator
  • Hero Member
  • *
  • Posts: 3644
  • Over $300 Donated to B3!
    • MordyT
Re: Run B3 as a FreeBSD Daemon
« Reply #1 on: May 25, 2011, 04:02:55 AM »
thanks for sharing!
Help will be given to those with a b3.log

If drop off the map it is due to RL becoming busy :)

System: Python 2.7.3 - Deb 7 - B3 Source Code - 128MB RAM box (rented at $5 a year) - remote MySQL - Remote Web Services

Offline Freelander

  • XLRstats dev.
  • Dev. Team
  • Hero Member
  • *
  • Posts: 1000
Re: Run B3 as a FreeBSD Daemon
« Reply #2 on: May 25, 2011, 01:57:49 PM »
Nice post, thanks for sharing!

Offline danlee

  • Newbie
  • *
  • Posts: 2
    • Dan Lee
Re: Run B3 as a FreeBSD Daemon
« Reply #3 on: May 26, 2011, 01:35:55 AM »
One thing I forgot to mention, when configuring b3.xml and other scripts.  Use absolute paths for all logs/files.  Otherwise freebsd will attempt to write to /usr/local/etc/rc.d.

Here is my b3.xml as an example:
Code: [Select]
        <settings name="b3">
                <set name="parser">bfbc2</set>
                <set name="database">mysql://b3:[email protected]/b3</set>
                <set name="bot_name">NNG</set>
                <set name="bot_prefix">^0(^2NNG^0)^7:</set>
                <set name="time_format">%I:%M%p %Z %m/%d/%y</set>
                <set name="time_zone">CEST</set>
                <set name="log_level">9</set>
                <set name="logfile">/var/log/b3/b3.log</set>
        <settings name="bfbc2">
                <set name="max_say_line_length">100</set>
        <settings name="server">
                <set name="public_ip">whatever</set>
                <set name="port">19567</set>
                <set name="rcon_ip">whatever</set>
                <set name="rcon_port">48888</set>
                <set name="rcon_password">something</set>
                <set name="timeout">3</set>
                <set name="punkbuster">on</set>
        <settings name="autodoc">
                <set name="type">xml</set>
                <set name="maxlevel">100</set>
                <set name="destination">/home/b3/bigbrotherbot/commands.xml</set>
        <settings name="messages">
                <set name="kicked_by">$clientname was kicked by $adminname $reason</set>
                <set name="kicked">$clientname was kicked $reason</set>
                <set name="banned_by">$clientname was banned by $adminname $reason</set>
                <set name="banned">$clientname was banned $reason</set>
                <set name="temp_banned_by">$clientname was temp banned by $adminname for $banduration $reason</set>
                <set name="temp_banned">$clientname was temp banned for $banduration $reason</set>
                <set name="unbanned_by">$clientname was un-banned by $adminname $reason</set>
                <set name="unbanned">$clientname was un-banned $reason</set>
        <settings name="plugins">
                <set name="external_dir">@b3/extplugins</set>
                <plugin name="spamcontrol" config="@conf/plugin_spamcontrol.xml"/>
                <plugin name="admin" config="@conf/plugin_admin.xml"/>
                <plugin name="pingwatch" config="@conf/plugin_pingwatch.xml" />
                <plugin name="adv" config="@conf/plugin_adv.xml"/>
                <plugin name="status" config="@conf/plugin_status.xml"/>
                <plugin name="welcome" config="@conf/plugin_welcome.xml"/>
                <plugin name="xlrstats" config="@conf/xlrstats.xml"/>
                <plugin name="ctime" config="@conf/plugin_ctime.xml"/>
                <plugin name="tk" config="@conf/plugin_tk.xml"/>
                <plugin name="autoreg" config="@conf/autoreg.xml"/>
                <plugin name="firstkill" config="@conf/firstkill.xml"/>
                <plugin name="chatlogger" config="@conf/plugin_chatlogger.xml"/>
                <plugin name="bfbc2mixedgames" config="@conf/bfbc2mixedgames.xml"/>
                <plugin name="poweradminbfbc2" config="@conf/poweradminbfbc2.xml"/>


Rate this page +1 at Google Search