killer-queen-stats / kqstats

Get real time statistics from your Killer Queen cabinets!
Other
25 stars 10 forks source link

Raspberry Pi support #20

Open KevinSnyderCodes opened 6 years ago

KevinSnyderCodes commented 6 years ago

kqstats can persistently run on a Raspberry Pi that is on the same network as the Killer Queen cabinet. This is beneficial for a number of reasons:

Getting this to work will be a multi-step process:

There may be other steps required.

Resources

whod81 commented 6 years ago

Just making some notes. I'm pretty sure there are some more apt-get's in here to get Node installed.

mDNS instructions:

Update Hostname (kqstats) and Update Pi

sudo vi /etc/hostname sudo vi /etc/hosts sudo apt-get update sudo apt-get -y dist-upgrade sudp apt-get -y install avahi-daemon build-essential reboot

Intall NODE-RED

bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

Get KQStats

git clone https://github.com/killer-queen-stats/kqstats cd kqstats

Node Install (This takes a while)

npm audit fix npm install

Create a service

sudo -s cat > /lib/systemd/system/kqstats.service << EOF [Unit] Description=KQ Stats After=multi-user.target

[Service] Type=simple User=pi WorkingDirectory=/home/pi/kqstats ExecStart=/bin/bash -ce 'exec /usr/bin/npm run start:debug -- -c ws://kq.local:12749 >> /home/pi/kqstats/logs/kqstats.log 2>&1' Restart=on-abort

[Install] WantedBy=multi-user.target EOF

Start Service

sudo systemctl daemon-reload sudo systemctl enable kqstats.service sudo systemctl start kqstats.service

whod81 commented 6 years ago

** Update *** This is no longer an issue if you run "npm audit fix" before doing the install..... node-sass is no longer a dependency.

Original Message

Current issue is that the npm install basically bricks the Pi. Need a way to cross-compile elsewhere and then deliver it.

This would help tremendously: https://github.com/sass/node-sass/issues/1609

whod81 commented 5 years ago
#!/bin/sh
REPODIR="/home/pi/repo"
HOMEDIR="/home/pi"
BRANCH=""

# Setting the nice value to as low priority as possible
# The npm install tends to hog up all resources

renice -n 10 $$

[[ `whoami` != "root" ]] && SUDO="/usr/bin/sudo"

if [[ ! -d ${REPODIR} ]]
then
    mkdir -p ${REPODIR}
fi

cd ${REPODIR}
[[ -d ${REPODIR}/kqstats ]] && ${SUDO} rm -rf ${REPODIR}/kqstats

if [[ ${BRANCH} ]]
then
    BRANCH_STR="-b ${BRANCH}"
fi

git clone  https://github.com/killer-queen-stats/kqstats ${BRANCH_STR}
cd ${REPODIR}/kqstats
npm audit fix
npm install
NPMRC=$?

if [[ ! -d ${REPODIR}/kqstats ]]
then
    echo "could not find ${REPODIR}/kqstats.  Exiting."
    exit 1
fi

if [[ $NPMRC == 0 ]]
then
    [[ -d ${HOMEDIR}/kqstats.3.old ]] && rm -rf ${HOMEDIR}/kqstats.3.old
    [[ -d ${HOMEDIR}/kqstats.2.old ]] && mv ${HOMEDIR}/kqstats.2.old ${HOMEDIR}/kqstats.3.old
    [[ -d ${HOMEDIR}/kqstats.1.old ]] && mv ${HOMEDIR}/kqstats.1.old ${HOMEDIR}/kqstats.2.old
    $SUDO systemctl stop kqstats.service
    [[ -d ${HOMEDIR}/kqstats ]] && mv ${HOMEDIR}/kqstats ${HOMEDIR}/kqstats.1.old
    mv ${REPODIR}/kqstats ${HOMEDIR}
    $SUDO chown -R pi:pi ${HOMEDIR}/kqstats
    $SUDO systemctl start kqstats.service
else
    echo "npm intall returned non-zero return code."
    exit 2
fi