github.com/influxdata/telegraf@v1.30.3/scripts/rpm/post-install.sh (about)

     1  #!/bin/bash
     2  
     3  # Remove legacy symlink, if it exists
     4  if [[ -L /etc/init.d/telegraf ]]; then
     5      rm -f /etc/init.d/telegraf
     6  fi
     7  
     8  # Add defaults file, if it doesn't exist
     9  if [[ ! -f /etc/default/telegraf ]]; then
    10      touch /etc/default/telegraf
    11  fi
    12  
    13  # Add .d configuration directory
    14  if [[ ! -d /etc/telegraf/telegraf.d ]]; then
    15      mkdir -p /etc/telegraf/telegraf.d
    16  fi
    17  
    18  # If 'telegraf.conf' is not present use package's sample (fresh install)
    19  if [[ ! -f /etc/telegraf/telegraf.conf ]] && [[ -f /etc/telegraf/telegraf.conf.sample ]]; then
    20     cp /etc/telegraf/telegraf.conf.sample /etc/telegraf/telegraf.conf
    21  fi
    22  
    23  # Set up log directories
    24  LOG_DIR=/var/log/telegraf
    25  mkdir -p $LOG_DIR
    26  chown -R -L telegraf:telegraf $LOG_DIR
    27  chmod 755 $LOG_DIR
    28  
    29  STATE_DIR=/var/lib/telegraf
    30  test -d "$STATE_DIR" || {
    31      mkdir -p "$STATE_DIR"
    32      chmod 770 "$STATE_DIR"
    33      chown root:telegraf "$STATE_DIR"
    34  }
    35  
    36  STATE_FILE="$STATE_DIR/statefile"
    37  test -f "$STATE_FILE" || {
    38      touch "$STATE_FILE"
    39      echo {} > "$STATE_FILE"
    40      chown root:telegraf "$STATE_FILE"
    41      chmod 660 "$STATE_FILE"
    42  }
    43  
    44  # Set up systemd service - check if the systemd directory exists per:
    45  # https://www.freedesktop.org/software/systemd/man/sd_booted.html
    46  if [[ -d /run/systemd/system ]]; then
    47      cp -f /usr/lib/telegraf/scripts/telegraf.service /usr/lib/systemd/system/telegraf.service
    48      systemctl enable telegraf
    49      systemctl daemon-reload
    50  fi