<commit_before>#!/usr/bin/env bash
RWHOD=(~/code/useless/rwho/rwhod.pl)
PIDFILE=~/tmp/rwhod-$(hostname).pid

if [[ -z $PERL5LIB ]]; then
	PERL5LIB=~/lib/perl5:~/usr/lib/perl5
fi
export PERL5LIB

ctl() {
	case $1 in
	start)
		"${RWHOD[@]}" & pid=$!
		echo $pid > "$PIDFILE"
		kill -0 $pid
		;;
	stop)
		pid=$(< "$PIDFILE") && kill $pid && rm "$PIDFILE"
		;;
	restart)
		ctl stop
		ctl start
		;;
	status)
		if [[ -f $PIDFILE ]] && pid=$(< "$PIDFILE"); then
			if kill -0 $pid; then
				echo "running: pid $pid"
			else
				echo "unsure: pid $pid but can't signal"
				return 2
			fi
		else
			echo "not running or no pidfile"
			return 1
		fi
	esac
}

ctl "$@"<commit_msg>make the .sh a little more like other initscripts<commit_after>#!/usr/bin/env bash
if (( $(id -u) > 0 )); then
	[[ $PIDFILE ]] ||
		export PIDFILE="$HOME/tmp/rwhod-$(hostname).pid"
	[[ $PERL5LIB ]] ||
		export PERL5LIB="$HOME/lib/perl5:$HOME/usr/lib/perl5"
else
	[[ $PIDFILE ]] ||
		export PIDFILE="/var/run/rwhod.pid"
fi

[[ $RWHOD_DIR ]] ||
	RWHOD_DIR="$HOME/code/useless/rwho"
[[ $RWHOD_OPTIONS ]] ||
	RWHOD_OPTIONS=()

ctl() {
	case $1 in
	start)
		"$RWHOD_DIR/rwhod.pl" "${RWHOD_OPTIONS[@]}" & pid=$!
		echo $pid > "$PIDFILE"
		kill -0 $pid
		;;
	stop)
		pid=$(< "$PIDFILE") && kill $pid && rm "$PIDFILE"
		;;
	restart)
		ctl stop
		ctl start
		;;
	status)
		if [[ -f $PIDFILE ]] && pid=$(< "$PIDFILE"); then
			if kill -0 $pid 2>/dev/null; then
				echo "running: pid $pid"
				return 0
			else
				echo "unsure: pid $pid but can't signal"
				return 2
			fi
		else
			echo "not running or no pidfile at '$PIDFILE'"
			return 1
		fi
	esac
}

ctl "$@"
{'fraction_non_alphanumeric': 0.19422249539028888, 'fraction_numerical': 0.013521819299323909, 'mean_word_length': 3.0098522167487687, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1281420', 'n_tokens_mistral': 798, 'n_tokens_neox': 695, 'n_words': 176}