| 1 | #!/sbin/openrc-run |
| 2 | |
| 3 | WORK_DIR="/" # btrfs filesytem root directory |
| 4 | DB_SIZE=8 # this default setting uses about 140M of memory |
| 5 | |
| 6 | BEESSTATUS=/run/$SVCNAME/$SVCNAME.status |
| 7 | BEESHOME="$WORK_DIR/.beeshome" |
| 8 | DB_PATH="$BEESHOME/beeshash.dat" |
| 9 | NEW_SIZE=$(expr $DB_SIZE \* 16777216) |
| 10 | name=$SVCNAME |
| 11 | command=/bin/$SVCNAME |
| 12 | command_args="$WORK_DIR" |
| 13 | command_background=yes |
| 14 | pidfile=/run/$SVCNAME/$SVCNAME.pid |
| 15 | export BEESSTATUS |
| 16 | |
| 17 | start_pre() { |
| 18 | checkpath -d /run/$SVCNAME |
| 19 | if [ ! -d "$BEESHOME" ]; then |
| 20 | btrfs sub cre "$BEESHOME" |
| 21 | fi |
| 22 | touch "$DB_PATH" |
| 23 | OLD_SIZE="$(wc -c < "$DB_PATH" | sed 's/\t/ /g' | cut -d' ' -f1)" |
| 24 | if [ "$OLD_SIZE" != "$NEW_SIZE" ]; then |
| 25 | truncate -s $NEW_SIZE $DB_PATH |
| 26 | fi |
| 27 | } |