Bokeh serve launched via crontab @reboot

Hello all,

I cannot seem to launch bokeh server from a crontab.

I realise this is not a bokeh issue, I have asked on stack exchange, but does anyone have a method so that once my server reboots bokeh also restarts?

So far I failed by calling from crontab using @ reboot the following bash script

#!/bin/bash
source ~/miniconda3/etc/profile.d/conda.sh
conda activate c19
cd bokeh/examples/app
bokeh serve c19 --allow-websocket-origins='example.com' --use-xheaders --port:5009 --prefix='/c19'

@awsbarker

The miniconda path in your script makes me think you’re running on an embedded Linux system such as a rpi.

I have had success running in a similar setup using systemd. It should work on any Linux distribution that supports systemd.

It is fairly straightforward to set up on a Linux-based device that supports systemd.

  1. Create a file that defines the service and copy that file to /lib/systemd/system

sudo cp my-app.service /lib/systemd/system/.

  1. Start the service

sudo systemctl start my-app

  1. Enable the service to run at boot

sudo systemctl enable my-app

The status of the service can be viewed with the following

service my-app status

Here’s an example of a service; the shell script referenced therein is a script that should execute that defines the functionality of the service. This should point to the bash script you’ve pasted into the topic; make sure that it has its execute attributes set, I believe.

my-app.service

[Unit]

Description=Bokeh web server service

After=network.target

StartLimitIntervalSec=0

[Service]

Type=simple

Restart=always

RestartSec=1

User=pi

ExecStart=/home/pi/dev/server/init/bk-web.sh

[Install]

WantedBy=multi-user.target

Thanks _jm,
I did create this app originally for RPi but as it developed the libraries pyproj associated with ARM were not available so I moved to Ubuntu x86-64.

Anyhow I did originally try systemd but the issue was still the script which won’t run the last line. So I guess my question should be How do you wrap the full bokeh serve command into a bash line?

I will try again based on your feedback and report back.

@awsbarker

I see. I don’t see why it doesn’t work by inspection. The following is an example of a script I was running as a service on an embedded Linux platform and it behaved as expected.

#!/bin/bash

BOKEHDIR=/home/pi/berryconda3/bin

APPDIR=/home/pi/dev/bkserver

PORT=5006

WEBSOCKET=*

LOCALHOST=y

$BOKEHDIR/bokeh serve $APPDIR/bkserver.py --port=$PORT --allow-websocket-origin=* --args --localhost=$LOCALHOST

I guess the only possible difference I see between your bash script and the one I used is that the path to bokeh is explicitly prescribed in my script. If the system running the script doesn’t know where to look for bokeh, that could cause the difference in behaviors we see.

So _jm,
It worked exactly as you originally wrote.
No problem with the last line in the bash script nor the systemd.service.
Many thanks.