github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/scripts/packages/post-install.sh (about)

     1  #!/bin/bash
     2  
     3  BIN_DIR=/usr/bin
     4  DATA_DIR=/var/lib/pyroscope
     5  LOG_DIR=/var/log/pyroscope
     6  SCRIPT_DIR=/usr/lib/pyroscope/scripts
     7  
     8  function install_init {
     9    cp -f $SCRIPT_DIR/init.sh /etc/init.d/pyroscope-server
    10    chmod +x /etc/init.d/pyroscope-server
    11  }
    12  
    13  function install_systemd {
    14    # Remove any existing symlinks
    15    rm -f /etc/systemd/system/pyroscope-server.service
    16  
    17    cp -f $SCRIPT_DIR/pyroscope-server.service /lib/systemd/system/pyroscope-server.service
    18  }
    19  
    20  function enable_systemd {
    21    systemctl enable pyroscope-server || true
    22    systemctl daemon-reload || true
    23  }
    24  
    25  function enable_update_rcd {
    26    update-rc.d pyroscope-server defaults
    27  }
    28  
    29  function enable_chkconfig {
    30    chkconfig --add pyroscope-server
    31  }
    32  
    33  id pyroscope &> /dev/null
    34  if [[ $? -ne 0 ]]; then
    35    useradd --system -U -M pyroscope -s /bin/false -d $DATA_DIR
    36  fi
    37  
    38  test -d $LOG_DIR || mkdir -p $LOG_DIR
    39  test -d $DATA_DIR || mkdir -p $DATA_DIR
    40  chown -R -L pyroscope:pyroscope $LOG_DIR
    41  chown -R -L pyroscope:pyroscope $DATA_DIR
    42  chmod 755 $LOG_DIR
    43  chmod 755 $DATA_DIR
    44  
    45  # Remove legacy symlink, if it exists
    46  if [[ -L /etc/init.d/pyroscope-server ]]; then
    47    rm -f /etc/init.d/pyroscope-server
    48  fi
    49  
    50  # Add defaults file, if it doesn't exist
    51  if [[ ! -f /etc/default/pyroscope ]]; then
    52    touch /etc/default/pyroscope
    53  fi
    54  
    55  # Distribution-specific logic
    56  if [[ -f /etc/redhat-release ]]; then
    57    # RHEL-variant logic
    58    which systemctl &>/dev/null
    59    if [[ $? -eq 0 ]]; then
    60      install_systemd
    61    else
    62      # Assuming sysv
    63      install_init
    64    fi
    65  elif [[ -f /etc/debian_version ]]; then
    66    # Debian/Ubuntu logic
    67    which systemctl &>/dev/null
    68    if [[ $? -eq 0 ]]; then
    69      install_systemd
    70    else
    71      # Assuming sysv
    72      install_init
    73    fi
    74  elif [[ -f /etc/os-release ]]; then
    75    source /etc/os-release
    76    if [[ $ID = "amzn" ]]; then
    77      # Amazon Linux logic
    78      which systemctl &>/dev/null
    79      if [[ $? -eq 0 ]]; then
    80        install_systemd
    81      else
    82        # Assuming sysv
    83        install_init
    84      fi
    85    fi
    86  fi