Crontab @reboot run bokeh-server apps

trying to run 2 bokeh apps on system reboot thru crontab, but failed to do so.

on crontab -e,
@reboot PATH/reboot_script1.sh
@reboot PATH/reboot_script2.sh

on reboot_script1.sh:
source /home/vcs_admin/anaconda3/etc/profile.d/conda.sh
conda activate base
cd PATH/bokeh project
bokeh serve project1 --address IP --port PORT --allow-websocket-origin URL:PORT --log-file file_log1.txt

on reboot_script2.sh:
source /home/vcs_admin/anaconda3/etc/profile.d/conda.sh
conda activate base
cd PATH/bokeh project
bokeh serve project2 --address IP --port PORT2 --allow-websocket-origin URL:PORT2 --log-file file_log2.txt

on above setup, it always runs the first one, i.e. project1, not project2. when interchange the position, then it runs project2, but not project1.

refer to some posts, the implementation can be done thru systemctl, but i yet to try. just wonder cannot do it thru crontab?

Thanks

@mhlearn

It has been some time since I used cron in favor of other system control tools. With that caveat, I believe your jobs are set up to run sequentially. Cron job1 (reboot_script1) runs and then job2 (reboot_script2) runs if job1 completes successfully.

The bokeh serve command of the first script you execute starts the server and runs it until it is terminated by design, so you’re never going to invoke the second job as currently organized.

I think you need to use & in your cron setup to run the two jobs in parallel (concurrently).

EDIT: Replaced && above with & to correct mis-stated syntax.

1 Like

@_jm thanks for you kind reply. the 2 jobs are supposed run parallel, independently and forever until itself failed.

i did try with, on crontab -e,
@reboot PATH/reboot_script1.sh && PATH/reboot_script2.sh
and also
@reboot PATH/reboot_script1.sh; PATH/reboot_script2.sh

but no luck, only the 1st job is running on both setup.

the goal was to automate manual tasks on running 2 bokeh apps when server reboot. what i always do, manually, i will open 2 terminal console, and run bokeh app command

on 1st terminal console:
bokeh serve project1 --address IP --port PORT --allow-websocket-origin URL:PORT --log-file file_log1.txt

on 2nd terminal console:
bokeh serve project2 --address IP --port PORT2 --allow-websocket-origin URL:PORT2 --log-file file_log2.txt

but it is troublesome, so i am trying to automate the tasks. I did some search and come across of cron job may able to achieve this, but now not sure if the cron job is the right choice to do so.

thanks

@mhlearn Several sources online seem to indicate that you need to put & after @reboot scripts in order for them to run in the background.

@Bryan thanks for the suggestion. I checked online and tried as well with below, but no luck. it is still only running the 1st job.

@reboot PATH/reboot_script1.sh && PATH/reboot_script2.sh &

Thanks

No, I mean use a single & after each:

@reboot PATH/reboot_script1.sh & 
@reboot PATH/reboot_script2.sh & 

The way you have it above will certainly still block forever on the first script.

@Bryan thanks for correcting me. Tried that, it does not work too.

from the netstat -lpn, can see the PORT for project1 is on listening state, but no PORT2 for project 2.

from systemctl status cron.service, noticed both project1 and project 2 @reboot command have been excecuted.

just no sure which part went wrong.

@mhlearn

Your original syntax works for me using cron on MacOSX Big Sur. This should not have anything to do with bokeh per se; however, in order verify I populated two simple scripts with bokeh serve commands and was able to navigate to both pages on reboot.

SHELL=/bin/zsh
@reboot job1.sh
@reboot job2.sh

If you are seeing problems with PORT and PORT2 environment variables, I would investigate whether your user environment is properly loaded when going through the cron mechanism. You could start by replacing those with distinct hardcoded variables (e.g. 5006 for job1 and 5008 for job2).

Also, do you see the logfiles you specified exist? do they have any info regarding bokeh server startup?

hi @_jm, i was trying on ubuntu 20.04.01 LTS os and both ports are harcoded 5008 and 5009. in my case, the log file for project1 is there when it is running.

i think it is not bokeh issue, just some place else, will investigate and try further.

thanks guys for the guidance.

@_jm, @Bryan. i got it run. it is access right issue. both scripts were with different access right.

thanks.