Question about cronjobs

Please tick the appropriate box to help us categorize your post
Bug or Error
Feature Request
Documentation Issue
Other

Hello everyone!

I’m working with Workbench AI and looking for help with automating the execution of a service. Specifically, I want to set up the “ollama serve” service to auto-start and run every minute.

I attempted to add ollama serve & directly to the postBuild.bash script, but it didn’t work as expected. My understanding of when and how the postBuild script runs is a bit unclear, so I’m wondering if there’s a simpler or more effective way to accomplish this task.

Here’s the part I’m using in my postBuild.bash:

curl -fsSL https://ollama.com/install.sh | sh
sudo sh -c 'echo "#!/bin/bash\npgrep -f \"ollama serve\" > /dev/null || ollama serve &" > /tmp/ollama_cron.sh' && \
sudo chmod +x /tmp/ollama_cron.sh && \
(sudo crontab -l 2>/dev/null; echo "* * * * * /tmp/ollama_cron.sh") | sudo crontab -

If there’s a better way to handle this, or if I’m approaching it incorrectly, I’d greatly appreciate any suggestions. Sorry if this is a bit of a basic question—I’m still learning the process.

Thanks so much for your time and assistance!

Why My Initial Approach Didn’t Work and How I Solved It with Multithreading

After further experimentation, I discovered why my initial method of adding ollama serve & directly to the postBuild.bash script and setting up a cron job wasn’t effective.

To resolve this, I implemented multithreading within the application itself to manage the execution of the ollama serve service. By handling service deployment directly through multithreading, the application gains better control over the workflow, can handle errors more gracefully, and ensures that ollama serve runs consistently. Additionally, this approach allows for easier integration of additional features and capabilities into the application.

This solution not only enhances the reliability of service management but also provides greater flexibility for future expansions. I hope this information helps anyone facing a similar challenge!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.