Skip to content

Instantly share code, notes, and snippets.

@NNdroid
Created December 22, 2022 00:37
Show Gist options
  • Select an option

  • Save NNdroid/81e83ed99491b751878ddf7df09d0563 to your computer and use it in GitHub Desktop.

Select an option

Save NNdroid/81e83ed99491b751878ddf7df09d0563 to your computer and use it in GitHub Desktop.
simply to install realtimetrafficd
#!/bin/bash
DOWNLOAD_URL="https://github.com/longsleep/realtimetraffic/releases/download/v0.2.0/realtimetrafficd-v0.2.0_amd64"
BIN_DST_DIR=/usr/local/bin
RUNNING_LISTENER=0.0.0.0:8006
function check_error() {
if [ $? == 1 ]; then
echo $1
exit 1
fi
}
function install() {
wget -O ${BIN_DST_DIR}/realtimetrafficd $DOWNLOAD_URL
check_error "download binary error!"
chmod +x ${BIN_DST_DIR}/realtimetrafficd
cat << EOT > /etc/systemd/system/realtimetrafficd.service
[unit]
Description=realtimetrafficd
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
Environment=GOGC=20
ExecStart=${BIN_DST_DIR}/realtimetrafficd -listen ${RUNNING_LISTENER}
Restart=on-failure
RestartSec=10
KillMode=process
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOT
systemctl enable --now realtimetrafficd
clear
echo "running on ${RUNNING_LISTENER}"
}
function remove() {
systemctl stop realtimetrafficd
systemctl disable realtimetrafficd
rm -rf /etc/systemd/system/realtimetrafficd.service
rm -rf ${BIN_DST_DIR}/realtimetrafficd
clear
echo "remove finished!"
}
function help() {
cat << EOF
realtimetrafficd install helper!!!
usage:
./realtimetrafficd.sh menu
install: install realtimetrafficd
remove: remove realtimetrafficd
EOF
}
function main() {
if [ $# -lt 1 ]; then
help
else
case $1 in
install)
install
;;
remove)
remove
;;
*)
echo 'command not found!'
help
;;
esac
fi
exit 0
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment