I created a simple project for those of you who are interested. I’m currently working on the oled services and need to constantly stop and start the service. For the guys out there also tinkering with this, I’d recommend following the following following post by @CAProjects on enabling a project from the settings menu.
After you have followed this tutorial on enabling the projects menu, navigate to /home/user and create yourself an oled projects folder if you haven’t already done so. Create a sub directory here and call it “Restart OLED” This will be the name that is displayed in the projects menu.
Once the folder has been created, we need to make a minimum of 1 file, but the way the projects folder works, we need 2 for completeness. Create the new files and call them:
start.sh
stop.sh
Now, open start.sh in a text editor of your choice and paste the following:
sudo systemctl restart pt-sys-oled.service
Save and close the text editor. No open a terminal in this folder and perform the following commands:
chmod u+x start.sh
chmod u+x stop.sh
This gives the scripts executable privileges.
You should be ready now. On the pi-top, press the circle button and get yourself to where it is showing “Settings” on the screen. Click the down button to navigate to projects. Press the circile button again on “Projects” You should be able to scroll through the list and find “Restart OLED.” Once you find it, press the circle button one more time and you should be able to see that the OLED goes blank after a few seconds and then comes back (granted you didn’t change anything and there are no errors.)
If it fails to come back, be sure to check out the system daemon log @ /var/log/daemon.log
to find out what happened when the service was attempting to restart.
Final note: if you don’t see “Restart OLED” in the projects folder, try backing out and then re-entering the projects folder. I found that sometimes when making a new folder, even though it is supposed to update right away, it doesn’t always. This forces it to refresh.
How this works:
The projects menu will start executing its own calling code the moment the user requests to run a particular project. This code checks to see if there are any scripts in your project directory currently running and if there is, will try to run the stop.sh
script from your project folder. If there is no stop.sh
script in your folder, then it will attempt to kill the process by finding its process id.
Once this is done, it will then start to execute start.sh
. If your bash script blocks indefinitely, then use the stop.sh
to clean things up. If you don’t use the stop.sh
script, then it will kill the process mid instruction regardless and can leave your project in an unknown state, like when reading or writing files, running a python script, etc etc. But if your project will terminate the moment the instruction is complete, there really is no need to use stop.h
If an instruction ever hangs or a program hangs after being called from the start.sh
, chances are you’re going to want to terminate that process anyways.
Enjoy!