<commit_before>#!/usr/bin/env bash
# Generate and install the SystemD service


DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )


# Make sure we are running as root
if [ "$(whoami)" != "root" ];
then
  echo "$(basename $0) must be run as root"
  exit 1
fi


# Configure some values
REALUSER=$(who am i | awk '{print $1}')
SERVICE="systemd"
FILENAME="charlotte.service"
FILEPATH="../etc/$SERVICE"


# Configure file path if it doesn't already exist
mkdir -p "$FILEPATH"
chown $REALUSER:$REALUSER "$FILEPATH"


# Generate the service file
cat << EOF > "$FILEPATH/$FILENAME"
[Unit]
Description=Manage Charlotte reporting daemon

[Service]
Type=oneshot
ExecStart=/usr/bin/env bash -c 'cd $PWD/..; \$PWD/bin/service-all.sh start'
ExecStop=/usr/bin/env bash -c 'cd $PWD/..; \$PWD/bin/service-all.sh stop'
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF


# Set ownership
chown $REALUSER:$REALUSER "$FILEPATH/$FILENAME"


# Link
ln -s "$FILEPATH/$FILENAME" "/etc/systemd/system/$FILENAME"


# Enable the service
systemctl enable charlotte.service
if [ "$?" -ne "0" ];
then
  echo 1>&2 "Failed to enable Charlotte service in Systemd"
  exit 1
fi


# Start the service
service charlotte start
if [ "$?" -ne "0" ];
then
  echo 1>&2 "Failed to start Charlotte service via Systemd"
  exit 1
fi<commit_msg>Iterating on service install<commit_after>#!/usr/bin/env bash
# Generate and install the SystemD service


DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )


# Make sure we are running as root
if [ "$(whoami)" != "root" ];
then
  echo "$(basename $0) must be run as root"
  exit 1
fi


# Configure some values
REALUSER=$(who am i | awk '{print $1}')
SERVICE="systemd"
FILENAME="charlotte.service"
FILEPATH="../etc/$SERVICE"


# Configure file path if it doesn't already exist
mkdir -p "$FILEPATH"
chown -R $REALUSER:$REALUSER "$FILEPATH"
if [ "$?" -ne "0" ];
then
  echo 1>&2 "Unable to set permission on service file path: '$FILEPATH'"
  exit 1
fi


# Generate the service file
cat << EOF > "$FILEPATH/$FILENAME"
[Unit]
Description=Manage Charlotte reporting daemon

[Service]
Type=oneshot
ExecStart=/usr/bin/env bash -c 'cd $PWD/..; \$PWD/bin/service-all.sh start'
ExecStop=/usr/bin/env bash -c 'cd $PWD/..; \$PWD/bin/service-all.sh stop'
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF

if [ "$?" -ne "0" ];
then
  echo 1>&2 "Failed to create service script: '$FILEPATH/$FILENAME'"
  exit 1
fi


# Set ownership
chown $REALUSER:$REALUSER "$FILEPATH/$FILENAME"
if [ "$?" -ne "0" ];
then
  echo 1>&2 "Unable to set permission on service file: '$FILEPATH/$FILENAME'"
  exit 1
fi


# Link
ln -s "$FILEPATH/$FILENAME" "/etc/systemd/system/$FILENAME"
if [ "$?" -ne "0" ];
then
  echo 1>&2 "Failed to create symlink for service file in: '/etc/systemd/system/$FILENAME'"
  exit 1
fi


# Enable the service
systemctl enable charlotte.service
if [ "$?" -ne "0" ];
then
  echo 1>&2 "Failed to enable Charlotte service in Systemd"
  exit 1
fi


# Start the service
service charlotte start
if [ "$?" -ne "0" ];
then
  echo 1>&2 "Failed to start Charlotte service via Systemd"
  exit 1
fi
{'fraction_non_alphanumeric': 0.151495657767771, 'fraction_numerical': 0.012865873271148279, 'mean_word_length': 4.090016366612112, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '893171', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1080, 'n_words': 365}