summaryrefslogtreecommitdiff
path: root/doc/rc.d_cccms
blob: 909b37278c40e674600f896b7da26273d11f480c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
#
# PROVIDE: cccms
# REQUIRE: LOGIN postgresql
# KEYWORD: shutdown

. /etc/rc.subr

name="cccms"
rcvar="cccms_enable"
desc="CCC CMS unicorn server"

cccms_dir="${cccms_dir:-/usr/local/www/cccms}"
rvm_ruby_version=$(cat ${cccms_dir}/.ruby-version 2>/dev/null || echo "ruby-3.2.11")
rvm_gemset=$(cat ${cccms_dir}/.ruby-gemset 2>/dev/null || echo "rails8-upgrade")
rvm_gemset_path="/usr/local/rvm/gems/${rvm_ruby_version}@${rvm_gemset}"

command="${rvm_gemset_path}/wrappers/unicorn"

cccms_unicorn_config="${cccms_unicorn_config:-/usr/local/etc/unicorn.rb}"

command_args="-c ${cccms_unicorn_config} -E production -D"
cccms_chdir="${cccms_dir}"

pidfile="${cccms_pidfile:-${cccms_dir}/tmp/pids/unicorn.pid}"
procname="ruby"

required_dirs="${cccms_dir}"

extra_commands="reload regenerate_occurrences"
sig_reload="USR2"

regenerate_occurrences_cmd="cccms_regenerate_occurrences"
cccms_regenerate_occurrences()
{
    cd ${cccms_dir} && \
    ${rvm_gemset_path}/wrappers/bundle \
        exec rails runner \
        'Event.find_each { |e| Occurrence.generate(e) }' \
        >> /var/log/unicorn.stderr.log 2>&1 && \
    touch /var/db/cccms_occurrences_regenerated
    echo "Occurrences regenerated."
}

start_precmd="cccms_prestart"
cccms_prestart()
{
    mkdir -p /usr/local/www/cccms/tmp/pids /var/log
    touch /var/log/unicorn.stderr.log
    chown www:www /var/log/unicorn.stderr.log
}

start_postcmd="cccms_poststart"
cccms_poststart()
{
    if [ -z "$(find /var/db/cccms_occurrences_regenerated -mtime -365 2>/dev/null)" ]; then
        echo "Occurrences stale or missing, regenerating..."
        cccms_regenerate_occurrences
    fi
}

export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
export RAILS_ENV=production
export HOME=/root

load_rc_config "${name}"
: ${cccms_enable:="NO"}

run_rc_command "$1"