Contribution: Running Cells as a service under FreeBSD

In the spirit of the current user manual, here is the script I use to start/stop Cells as a service inside a FreeBSD box. Feel free to copy, comment, or change it; consider it being in the public domain (if you use it), no credits necessary.

Actually killing the Cells process(es) is tricky, so I’m using a ‘nuclear option’ here — try to use cells stop, then send a SIGHUP to the remaining processes, and finally zap them with a SIGTERM. In my experience, Cells forks tons of processes, and not all get killed when using cells stop

Tested under FreeBSD 11.2-RELEASE-p10.

/etc/rc.conf:

[...]
pydio_cells_enable="YES"
pydio_cells_flags="--log production"
[...]

/usr/local/etc/rc.d/pydio-cells (make sure this script file is owned by root:wheel and that it’s set as executable), change the paths for command and pydio_cells_log according to your own setup:

#!/bin/sh
#
# PROVIDE: pydio_cells
# REQUIRE: DAEMON

# Add the following lines to /etc/rc.conf to enable pydio_cells:
# pydio_cells_enable="YES"
# pydio_cells_flags="<set as needed>"

. /etc/rc.subr

name="pydio_cells"
rcvar=pydio_cells_enable

command="/root/go/bin/cells"
pydio_cells_log="/root/.config/Pydio/cells/logs/cells.log"

extra_commands="restart"

pidfile="/var/run/cells.pid"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
restart_cmd="${name}_restart"
poll_cmd=":"
status_cmd=":"

load_rc_config ${name}
: ${pydio_cells_enable:=no}
: ${pydio_cells_flags:=""}

pydio_cells_start() {
        echo "starting ${name}."
        TERM=screen-256color
        /usr/sbin/daemon -o ${pydio_cells_log} -P ${pidfile} ${command} start ${pydio_cells_flags}
}

pydio_cells_stop() {
        echo "stopping ${name}."
        TERM=screen-256color
        ${command} stop >> ${pydio_cells_log} 2>&1
        /bin/kill -1 `/bin/cat ${pidfile}`
        /usr/bin/killall -9 cells       # for good measure
}

pydio_cells_restart() {
        echo "restarting ${name}."
        pydio_cells_stop
        pydio_cells_start
}

run_rc_command "$1"

You’ll probably also want to run newsyslog to trim the Cells logs periodically, so drop the following lines to /etc/newsyslog.conf.d/pydio-cells.newsyslog.conf (tweaking as needed):

# logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
/root/.config/Pydio/cells/logs/*.log    640  6    10000 $W6D0 GJ     /var/run/cells.pid
2 Likes