MagicMirror/Installation
From r00tedvw.com wiki
(Difference between revisions)
| (8 intermediate revisions by one user not shown) | |||
| Line 2: | Line 2: | ||
Create executable | Create executable | ||
<nowiki>~$ mkdir -p /opt/MagicMirrorScreen | <nowiki>~$ mkdir -p /opt/MagicMirrorScreen | ||
| − | touch /opt/ | + | touch /opt/MagicMirrorUtils/magicmirrorscreen.sh |
| − | chmod +x /opt/ | + | chmod +x /opt/MagicMirrorUtils/magicmirrorscreen.sh</nowiki> |
| − | <code>~$ vim /opt/ | + | <code>~$ vim /opt/MagicMirrorUtils/magicmirrorscreen.sh</code> |
<nowiki>#\bin\bash | <nowiki>#\bin\bash | ||
export DISPLAY=:0 | export DISPLAY=:0 | ||
| Line 20: | Line 20: | ||
[Service] | [Service] | ||
| − | ExecStart=/bin/bash /opt/ | + | ExecStart=/bin/bash /opt/MagicMirrorUtils/magicmirrorscreen.sh |
User=pi | User=pi | ||
| Line 29: | Line 29: | ||
<nowiki>~$ ln -s /lib/systemd/system/magicmirrorscreen.service /etc/systemd/system/magicmirrorscreen.service</nowiki> | <nowiki>~$ ln -s /lib/systemd/system/magicmirrorscreen.service /etc/systemd/system/magicmirrorscreen.service</nowiki> | ||
| − | + | Reload service daemon and enable service | |
<nowiki>~$ systemctl daemon-reload | <nowiki>~$ systemctl daemon-reload | ||
~$ systemctl enable magicmirrorscreen.service</nowiki> | ~$ systemctl enable magicmirrorscreen.service</nowiki> | ||
| + | |||
| + | =Custom service to clear logs nightly= | ||
| + | Create the script | ||
| + | <nowiki>~$ mkdir -p /opt/MagicMirrorUtils | ||
| + | ~$ touch /opt/MagicMirrorUtils/clearlogs.sh | ||
| + | ~$ chmod +x /opt/MagicMirrorUtils/clearlogs.sh</nowiki> | ||
| + | Create the script <code>/opt/MagicMirrorUtils/clearlogs.sh</code> | ||
| + | <nowiki>#!/bin/bash | ||
| + | |||
| + | # Define an array with the full paths of the files to delete | ||
| + | files=( | ||
| + | "/var/log/magicmirror.log" | ||
| + | "/root/.pm2/logs/mm-error.log" | ||
| + | "/root/.pm2/pm2.log" | ||
| + | "/root/.pm2/logs/mm-out.log" | ||
| + | ) | ||
| + | |||
| + | # Loop through each item in the array and delete the file | ||
| + | for file in "${files[@]}"; do | ||
| + | if [ -f "$file" ]; then | ||
| + | echo "$(date +"%b %e %H:%M:%S"): MagicMirrorUtils\clearlogs.sh: Deleting $file" >> /var/log/messages | ||
| + | rm -rf "$file" | ||
| + | else | ||
| + | echo "$(date +"%b %e %H:%M:%S"): MagicMirrorUtils\clearlogs.sh: File $file does not exist." >> /var/log/messages | ||
| + | fi | ||
| + | done</nowiki> | ||
| + | |||
| + | Create the service | ||
| + | <code>/lib/systemd/system/magicmirrorclearlogs.service</code> | ||
| + | <nowiki>[Unit] | ||
| + | Description=Nightly Task To Clear MagicMirror And Related Logs | ||
| + | |||
| + | [Service] | ||
| + | Type=oneshot | ||
| + | ExecStart=/opt/MagicMirrorUtils/clearlogs.sh | ||
| + | User=root</nowiki> | ||
| + | |||
| + | Create the timer | ||
| + | <code>/lib/systemd/system/magicmirrorclearlogs.timer</code> | ||
| + | <nowiki>[Unit] | ||
| + | Description=Run Nightly Task | ||
| + | |||
| + | [Timer] | ||
| + | OnCalendar=02:00:00 | ||
| + | Persistent=true | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=timers.target</nowiki> | ||
| + | |||
| + | Create Symlink | ||
| + | <nowiki>~$ ln -s /lib/systemd/system/magicmirrorclearlogs.service /etc/systemd/system/magicmirrorclearlogs.service</nowiki> | ||
| + | |||
| + | Reload service daemon | ||
| + | <nowiki>~$ systemctl daemon-reload</nowiki> | ||
| + | |||
| + | Enable and start the timer | ||
| + | <nowiki>systemctl enable magicmirrorclearlogs.timer | ||
| + | systemctl start magicmirrorclearlogs.timer</nowiki> | ||
Latest revision as of 03:09, 5 June 2024
[edit] Custom service to turn on screen
Create executable
~$ mkdir -p /opt/MagicMirrorScreen touch /opt/MagicMirrorUtils/magicmirrorscreen.sh chmod +x /opt/MagicMirrorUtils/magicmirrorscreen.sh
~$ vim /opt/MagicMirrorUtils/magicmirrorscreen.sh
#\bin\bash
export DISPLAY=:0
while true; do
xset s reset
sleep 60
done
Create Service
~$ touch /lib/systemd/system/magicmirrorscreen.service
[Unit] Description=example systemd service unit file. After=magicmirror.service [Service] ExecStart=/bin/bash /opt/MagicMirrorUtils/magicmirrorscreen.sh User=pi [Install] WantedBy=multi-user.target
Create Symlink
~$ ln -s /lib/systemd/system/magicmirrorscreen.service /etc/systemd/system/magicmirrorscreen.service
Reload service daemon and enable service
~$ systemctl daemon-reload ~$ systemctl enable magicmirrorscreen.service
[edit] Custom service to clear logs nightly
Create the script
~$ mkdir -p /opt/MagicMirrorUtils ~$ touch /opt/MagicMirrorUtils/clearlogs.sh ~$ chmod +x /opt/MagicMirrorUtils/clearlogs.sh
Create the script /opt/MagicMirrorUtils/clearlogs.sh
#!/bin/bash
# Define an array with the full paths of the files to delete
files=(
"/var/log/magicmirror.log"
"/root/.pm2/logs/mm-error.log"
"/root/.pm2/pm2.log"
"/root/.pm2/logs/mm-out.log"
)
# Loop through each item in the array and delete the file
for file in "${files[@]}"; do
if [ -f "$file" ]; then
echo "$(date +"%b %e %H:%M:%S"): MagicMirrorUtils\clearlogs.sh: Deleting $file" >> /var/log/messages
rm -rf "$file"
else
echo "$(date +"%b %e %H:%M:%S"): MagicMirrorUtils\clearlogs.sh: File $file does not exist." >> /var/log/messages
fi
done
Create the service
/lib/systemd/system/magicmirrorclearlogs.service
[Unit] Description=Nightly Task To Clear MagicMirror And Related Logs [Service] Type=oneshot ExecStart=/opt/MagicMirrorUtils/clearlogs.sh User=root
Create the timer
/lib/systemd/system/magicmirrorclearlogs.timer
[Unit] Description=Run Nightly Task [Timer] OnCalendar=02:00:00 Persistent=true [Install] WantedBy=timers.target
Create Symlink
~$ ln -s /lib/systemd/system/magicmirrorclearlogs.service /etc/systemd/system/magicmirrorclearlogs.service
Reload service daemon
~$ systemctl daemon-reload
Enable and start the timer
systemctl enable magicmirrorclearlogs.timer systemctl start magicmirrorclearlogs.timer