Difference between revisions of "Web Kiosk CentOS 7"

From Michael's Information Zone
Jump to navigation Jump to search
 
(44 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
Powers that be wanted a TV mounted in a lobby, with content playing on it for visitors to ignore. At first I was told to install a flash drive and play images with the flush mount TV. Instead I thought it would be a good idea to have a NUC installed behind the TV running a web browser in full screen mode, displaying a WordPress site that my boss could manage (He really likes wordpress).
+
Boot into Chrome Kiosk mode and display a web page for digital signage.
==Hardware==
 
Intel BOXNUC6CAYH
 
<br>
 
-2GB DDR3 RAM (I had laying around, should be enough to display a single web page and run the background tasks)
 
<br>
 
-Intel(R) Celeron(R) CPU J3455 @ 1.50GHz (Came with the NUC. Just enough to display a web page and run WordPress)
 
<br>
 
-KingDian S100 16GB SSD (This was dirt cheap, and will probably die with the lack of RAM installed.)
 
<br>
 
<br>
 
This is connected to the wifi since there is no ethernet installed behind the TV. But since the site is on the unit I can live with broken connections. A simple script later on should take care of this.
 
  
 
==Setup==
 
==Setup==
 
===Packages===
 
===Packages===
A fresh install of CentOS 7, and the usual basics. Please note the following
+
A fresh install of CentOS 7 minimal. Please note the following
*x11 server did not install with the group install of Xfce, so it was installed seperately.
+
*x11 server did not install with the group install of Xfce, so it was installed separately.
*<ref>https://bbs.archlinux.org/viewtopic.php?id=225780</ref>Keyboard and mouse did not work out the box, and I had to install the evdev drivers. Granted no one should be using a keyboard and mouse with this system, but I will be running VNC as an extra method for managing the system (Windows weenies will be asking fewer questions this way.)
+
*<ref>https://bbs.archlinux.org/viewtopic.php?id=225780</ref>Keyboard and mouse did not work out the box, and I had to install the evdev drivers.
 +
====Base Packages====
 
<pre>
 
<pre>
 
yum -y update
 
yum -y update
 
yum -y install epel-release
 
yum -y install epel-release
 
yum makecache
 
yum makecache
yum -y install htop nano xorg-x11-server-Xorg smartmontools chromium xorg-x11-drv-evdev wget httpd mysql php mariadb-server php-mysql
+
yum -y install chromium wget zstd xorg-x11-xinit NetworkManager-wifi
 +
</pre>
 +
 
 +
====XFCE====
 +
<pre>
 
yum -y group install Xfce
 
yum -y group install Xfce
 +
yum -y install xorg-x11-drv-evdev xorg-x11-server-Xorg
 +
</pre>
 +
 +
====OpenBox (Preferred)====
 +
<ref>http://xinerama.blogspot.com/2018/09/installing-openbox-on-centos-75.html</ref>
 +
<pre>
 +
yum install -y openbox xorg-x11-drv-libinput xorg-x11-server-utils xorg-x11-xinit libev
 
</pre>
 
</pre>
 +
 +
====Unclutter====
 
*Install unclutter<ref>https://www.archlinux.org/packages/community/x86_64/unclutter/</ref><ref>https://stackoverflow.com/questions/660613/how-do-you-hide-the-mouse-pointer-under-linux-x11</ref>, this is useful for getting rid of the mouse pointer when not in use.
 
*Install unclutter<ref>https://www.archlinux.org/packages/community/x86_64/unclutter/</ref><ref>https://stackoverflow.com/questions/660613/how-do-you-hide-the-mouse-pointer-under-linux-x11</ref>, this is useful for getting rid of the mouse pointer when not in use.
 +
*NOTE: I ran into issues downloading from archlinux, quick and dirty google search had me run across a git repo.<ref>https://ostechnix.com/auto-hide-mouse-pointer-using-unclutter-after-a-certain-time/#:~:text=Auto%20Hide%20Mouse%20Pointer%20Using%20Unclutter%20After%20A%20Certain%20Time%20In%20Linux&text=If%20the%20mouse%20cursor%20has,after%205%20seconds%20by%20default.</ref>
 +
=====Repo method=====
 +
This has not been fully tested and may contain bad code.
 
<pre>
 
<pre>
wget -O unclutter.tar https://www.archlinux.org/packages/community/x86_64/unclutter/download/
+
yum install -y git libev-devel libX11-devel libXt-devel libXi-devel asciidoc
 +
yum groupinstall "Development Tools"
 +
git clone https://github.com/Airblader/unclutter-xfixes && cd unclutter-xfixes
 +
mkdir /usr/share/licenses/unclutter/
 +
make
 +
make install
 +
</pre>
 +
=====Arch method=====
 +
<pre>
 +
wget -O unclutter.tar.zst --content-disposition --max-redirect=5 https://www.archlinux.org/packages/community/x86_64/unclutter/download/
 +
zstd -d unclutter.tar.zst -o unclutter.tar
 
tar -xf unclutter.tar
 
tar -xf unclutter.tar
 
mv usr/bin/unclutter /usr/bin/unclutter
 
mv usr/bin/unclutter /usr/bin/unclutter
 
rm -rf usr
 
rm -rf usr
</pre>
 
*Start the services and prep for config
 
<pre>
 
systemctl enable httpd
 
systemctl enable mariadb
 
systemctl start httpd
 
systemctl start mariadb
 
mysql -e "UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';"
 
mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
 
mysql -e "DELETE FROM mysql.user WHERE User='';"
 
mysql -e "DROP DATABASE test;"
 
mysql -e "create database wordpress;"
 
mysql -e "grant all privileges on wordpress.* to 'wordpress'@'%' identified by 'password';"
 
mysql -e "FLUSH PRIVILEGES;"
 
</pre>
 
*Loosen SELinux. Normall you don't do this, but for something as simple as this I am ok with it.
 
<pre>
 
setsebool -P httpd_unified 1
 
 
</pre>
 
</pre>
  
 
===TTY1 Autologin===
 
===TTY1 Autologin===
 +
====TTY Config====
 
Now create the auto-login process.
 
Now create the auto-login process.
 
<pre>
 
<pre>
Line 69: Line 68:
 
fi
 
fi
 
EOF
 
EOF
 
+
</pre>
cat << EOF>>/hom/publicuser/.xinitrc
+
====Auto Start Window Manager====
exec startxfce4
+
*Choose which one you want, startxfce4 or openbox-session.
 +
<pre>
 +
cat << EOF>>/home/publicuser/.xinitrc
 +
exec openbox-session
 
EOF
 
EOF
 
reboot
 
 
</pre>
 
</pre>
After the reboot, you should see the desktop start up. If it does not troubleshoot.
+
Reboot and you should see the desktop start up. If it does not troubleshoot.
  
===Configure Chromium Auto-start===
+
===Configure Chromium Auto-Start===
*Make sure to have DNS entries for your site. I am using hosts entries on the computer since it is remote and will not have access to DNS, but will create a DNS entry for management purposes.
+
====XFCE====
 
<ref>https://www.danpurdy.co.uk/web-development/raspberry-pi-kiosk-screen-tutorial/</ref><ref>https://superuser.com/questions/461035/disable-google-chrome-session-restore-functionality</ref>
 
<ref>https://www.danpurdy.co.uk/web-development/raspberry-pi-kiosk-screen-tutorial/</ref><ref>https://superuser.com/questions/461035/disable-google-chrome-session-restore-functionality</ref>
 
<pre>
 
<pre>
Line 94: Line 94:
 
Categories=
 
Categories=
 
OnlyShowIn=XFCE;
 
OnlyShowIn=XFCE;
 +
EOF
 +
</pre>
 +
 +
====OpenBox====
 +
<pre>
 +
mkdir -p /home/publicuser/.config/openbox
 +
 +
cat << EOF > /home/publicuser/.config/openbox/autostart
 +
/usr/bin/xset -dpms s off s noblank &
 +
/usr/bin/chromium-browser --user-data-dir=/home/publicuser --noerrdialogs --kiosk https://site.tld/webpage &
 +
/usr/bin/unclutter &
 
EOF
 
EOF
 
</pre>
 
</pre>
  
 
===Configure Power Settings and Disable Mouse Pointer===
 
===Configure Power Settings and Disable Mouse Pointer===
 +
*<b>NOTE :</b> This is configured for xfce. Another set of instructions will follow for openbox.
 
We want to prevent the system from going to sleep, blanking the screen, loading the screen saver<ref>https://superuser.com/questions/644804/disable-screensaver-screen-blank-via-command-line</ref>, or showing the pointer on the screen.
 
We want to prevent the system from going to sleep, blanking the screen, loading the screen saver<ref>https://superuser.com/questions/644804/disable-screensaver-screen-blank-via-command-line</ref>, or showing the pointer on the screen.
 +
<br>
 +
One issue I am having is understanding the best method for exporting the display. I am too used to working in bash and not with a gui. The following export does not work, but the display settings appear to still work.
 +
<br>
 +
Initially the xset commands were getting ignored by xfce power management. In order to get around this I had to use xfconf-query<ref>https://askubuntu.com/questions/407287/change-xfce4-power-manager-option-from-terminal</ref> to make things stick
 
*Create the script
 
*Create the script
 
<pre>
 
<pre>
Line 105: Line 121:
 
sleep 10
 
sleep 10
 
export DISPLAY=$(who | grep -E "publicuser pts\/[0-9]" | grep -Eo "\(:[0-9][.]?[0-9]?\)" | sed 's/(//; s/)//')
 
export DISPLAY=$(who | grep -E "publicuser pts\/[0-9]" | grep -Eo "\(:[0-9][.]?[0-9]?\)" | sed 's/(//; s/)//')
xset s off
+
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/dpms-enabled -s false
xset s noblank
 
xset -dpms
 
 
/usr/bin/unclutter -grab
 
/usr/bin/unclutter -grab
 
EOF
 
EOF
  
 
chmod +x /home/publicuser/power.sh
 
chmod +x /home/publicuser/power.sh
 +
sed -i 's/<\/property>/\ \ <property\ name=\"blank-on-ac\"\ type=\"int\"\ value=\"0\"\/>\n&/g' /home/publicuser/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-power-manager.xml
 
</pre>
 
</pre>
 
*Create the auto-launch of the script.
 
*Create the auto-launch of the script.
Line 127: Line 142:
 
Categories=
 
Categories=
 
OnlyShowIn=XFCE;
 
OnlyShowIn=XFCE;
 +
EOF
 +
</pre>
 +
===Reload Chromium via CRON===
 +
Ran into an issue with flaky wifi and Chromium not reloading the page during a gateway timeout. Add a cron job for publicuser with the following
 +
<pre>
 +
@hourly DISPLAY=:0 /home/publicuser/restart.sh
 
</pre>
 
</pre>
 
+
Create the restart script at /home/publicuser/restart.sh
===Setup WordPess===
 
But first I download and extract the files needed over ssh.
 
 
<pre>
 
<pre>
wget https://wordpress.org/latest.zip
+
#!/bin/bash
unzip latest.zip
+
killall chromium-browser
mv wordpress /var/www/html/
+
sleep 1
find /var/www/html/wordpress/ -type d -exec chmod 755 {} \;
+
/usr/bin/chromium-browser --user-data-dir=/home/publicuser --noerrdialogs --kiosk https://site.tld/webpage &
find /var/www/html/wordpress/ -type f -exec chmod 644 {} \;
 
mkdir /var/www/html/wordpress/logs
 
chown -R apache:apache /var/www/html/wordpress
 
 
 
 
</pre>
 
</pre>
*Setup a vhost to load the site.
+
Mark executable
 
<pre>
 
<pre>
cat << EOF >>/etc/httpd/conf.d/vhost.conf
+
chmod u+x /home/publicuser/restart.sh
<VirtualHost *:80>
 
ServerName localhost
 
DocumentRoot "/var/www/html/wordpress"
 
</VirtualHost>
 
EOF
 
 
</pre>
 
</pre>
*Up until now I have been setting this up remotely, however I will now need to start using the ol' keyboard and mouse so I can configure using localhost. Follow the standard wordpress setup<ref>https://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Installation</ref>.
 

Latest revision as of 12:43, 18 May 2022

Purpose

Boot into Chrome Kiosk mode and display a web page for digital signage.

Setup

Packages

A fresh install of CentOS 7 minimal. Please note the following

  • x11 server did not install with the group install of Xfce, so it was installed separately.
  • [1]Keyboard and mouse did not work out the box, and I had to install the evdev drivers.

Base Packages

yum -y update
yum -y install epel-release
yum makecache
yum -y install chromium  wget zstd xorg-x11-xinit NetworkManager-wifi

XFCE

yum -y group install Xfce
yum -y install xorg-x11-drv-evdev xorg-x11-server-Xorg

OpenBox (Preferred)

[2]

yum install -y openbox xorg-x11-drv-libinput xorg-x11-server-utils xorg-x11-xinit libev

Unclutter

  • Install unclutter[3][4], this is useful for getting rid of the mouse pointer when not in use.
  • NOTE: I ran into issues downloading from archlinux, quick and dirty google search had me run across a git repo.[5]
Repo method

This has not been fully tested and may contain bad code.

yum install -y git libev-devel libX11-devel libXt-devel libXi-devel asciidoc 
yum groupinstall "Development Tools"
git clone https://github.com/Airblader/unclutter-xfixes && cd unclutter-xfixes
mkdir /usr/share/licenses/unclutter/
make
make install
Arch method
wget -O unclutter.tar.zst --content-disposition --max-redirect=5 https://www.archlinux.org/packages/community/x86_64/unclutter/download/
zstd -d unclutter.tar.zst -o unclutter.tar
tar -xf unclutter.tar
mv usr/bin/unclutter /usr/bin/unclutter
rm -rf usr

TTY1 Autologin

TTY Config

Now create the auto-login process.

useradd publicuser
rm /etc/systemd/system/getty.target.wants/getty@tty1.service
cp /lib/systemd/system/getty@.service /etc/systemd/system/getty@tty1.service
sed -i -e "s/\/sbin\/agetty/\0 --autologin publicuser/" /etc/systemd/system/getty@tty1.service
ln -s /etc/systemd/system/getty@tty1.service /etc/systemd/system/getty.target.wants/getty@tty1.service

cat << EOF >>/home/publicuser/.bash_profile
if [[ -z \$DISPLAY ]] && [[ \$(tty) = /dev/tty1 ]]; then # Check if we have a display and we're on TTY1
startx
else
echo "Please contact the help desk and provide the following"
echo "IP : "
echo "Hostname : $hostname"
fi
EOF

Auto Start Window Manager

  • Choose which one you want, startxfce4 or openbox-session.
cat << EOF>>/home/publicuser/.xinitrc
exec openbox-session
EOF

Reboot and you should see the desktop start up. If it does not troubleshoot.

Configure Chromium Auto-Start

XFCE

[6][7]

cat << EOF>>/etc/xdg/autostart/kiosk.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Kiosk
GenericName=program
Comment=LobbyKiosk
Exec=chromium-browser --noerrdialogs --kiosk http://siteurl.tld
Icon=/usr/share/pixmaps/program.jpg
Terminal=false
Type=Application
Categories=
OnlyShowIn=XFCE;
EOF

OpenBox

mkdir -p /home/publicuser/.config/openbox

cat << EOF > /home/publicuser/.config/openbox/autostart
/usr/bin/xset -dpms s off s noblank &
/usr/bin/chromium-browser --user-data-dir=/home/publicuser --noerrdialogs --kiosk https://site.tld/webpage &
/usr/bin/unclutter &
EOF

Configure Power Settings and Disable Mouse Pointer

  • NOTE : This is configured for xfce. Another set of instructions will follow for openbox.

We want to prevent the system from going to sleep, blanking the screen, loading the screen saver[8], or showing the pointer on the screen.
One issue I am having is understanding the best method for exporting the display. I am too used to working in bash and not with a gui. The following export does not work, but the display settings appear to still work.
Initially the xset commands were getting ignored by xfce power management. In order to get around this I had to use xfconf-query[9] to make things stick

  • Create the script
cat << EOF>>/home/publicuser/power.sh
#!/bin/sh
sleep 10
export DISPLAY=$(who | grep -E "publicuser pts\/[0-9]" | grep -Eo "\(:[0-9][.]?[0-9]?\)" | sed 's/(//; s/)//')
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/dpms-enabled -s false
/usr/bin/unclutter -grab
EOF

chmod +x /home/publicuser/power.sh
sed -i 's/<\/property>/\ \ <property\ name=\"blank-on-ac\"\ type=\"int\"\ value=\"0\"\/>\n&/g' /home/publicuser/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-power-manager.xml
  • Create the auto-launch of the script.
cat << EOF>>/etc/xdg/autostart/power.desktop
[Desktop Entry]
Encoding=UTF-8
Name=powersettings
GenericName=program3
Comment=DisablePower
Exec=/home/publicuser/power.sh
Icon=/usr/share/pixmaps/program.jpg
Terminal=false
Type=Application
Categories=
OnlyShowIn=XFCE;
EOF

Reload Chromium via CRON

Ran into an issue with flaky wifi and Chromium not reloading the page during a gateway timeout. Add a cron job for publicuser with the following

@hourly DISPLAY=:0 /home/publicuser/restart.sh

Create the restart script at /home/publicuser/restart.sh

#!/bin/bash
killall chromium-browser
sleep 1
/usr/bin/chromium-browser --user-data-dir=/home/publicuser --noerrdialogs --kiosk https://site.tld/webpage &

Mark executable

chmod u+x /home/publicuser/restart.sh