On this page I will show you how I am running a KNIME workflow once every day using systemctl on a UNIX Ubuntu system.
Of course, if you have KNIME Business Hub you can schedule any workflow directly from there, this article is for 'us poor guys and girls' who don't.
The workflow I want to execute in this example is called NOAA_LOOP_4. The purpose of this workflow is to load new USA temperature data from the NOAA website into my Climate Change data store.
Step 1 : create a shell script file (in this example noaa.sh) with the following content: (you will have to adapt this according to which version of KNIME you are using and to where your workflow is stored.)
#!/bin/bash
export DISPLAY=:0
/root/knime_5.9.0/knime -nosave -nosplash -reset -application org.knime.product.KNIME_BATCH_APPLICATION -workflowDir="/root/knime-workspace/batchexecute/NOAA_LOOP_4"
Step 2: create the file noaa.service in the /etc/systemd/system directory with the following content:
[Unit]
Description=Run NOAA Data Script
[Service]
Type=oneshot
ExecStart=/root/noaa.sh
# Optional: specify the user to run as
# User=yourusername
[Install]
WantedBy=multi-user.target
Step 3: create the file noaa.timer in the /etc/systemd/system directory with the following content:
This will 'call' the noaa.service every day at 16h15
[Unit]
Description=Daily timer for NOAA script
[Timer]
# Schedule for 16:15 every day
OnCalendar=*-*-* 16:15:00
# Ensures the job runs if the system was off during the scheduled time
Persistent=true
Unit=noaa.service
[Install]
WantedBy=timers.target
Step 4: execute the command sudo systemctl daemon-reload to make systemd aware of the changes you made.
To test-run your newly created service, you can execute the command sudo systemctl start noaa.service
To check the log files for each daily execution (very useful for debugging!) , execute the command journalctl -u noaa.service --no-pager
This will show the accumulated log file for every execution, if you want to 'clean out' the logs to see only the most recent execution, execute the 2 following commands: Beware that these commands will 'reset' the log file for ALL services controlled by systemctl, not just our noaa.service!
sudo journalctl --rotate
sudo journalctl --vacuum-time=1s