Cron @reboot not working

My cron @reboot is doing some weird things. I have a script to start my mumble bot that gets executed by @reboot but the bot never gets run. I've manually run the script with both relative and absolute paths and it works fine. I have other @reboot jobs running that work just fine but not this one. I added /bin/sleep 100 to the script before the script runs the bot just to see if the cronjob was being run. I rebooted, went into htop and sure enough the sleep was running as the correct user. I waited 100 seconds and then the process tree returns completely ignoring the second command in the script. I decided to move the sleep so it ran after the bot got started which should never happen since the bot wouldn't return. I reboot, go into htop and the sleep is running but the bot isn't. I tried doing cmd >> log.txt 2>&1 in my start script in hopes to catch the stdout and stderr streams but no file is ever created. If I do cat /var/log/syslog I get Aug 24 19:08:49 mumble-server CRON[690]: (mumbledj) CMD (/opt/mumbledj/start.sh) so it says it's being run. I even went as far as to add sudo -u mumbledj /opt/mumbledj/start.sh to /etc/rc.local. Sure enough that works and the bot runs no problem. I might create a systemd service for the bot but I'm more curious to know what exactly the issue is.

Whats the cron entry?

It's @reboot /opt/mumbledj/start.sh. start.sh just contains /opt/mumbledj/mumbledj_linux_amd64 -c /opt/mumbledj/config.yaml. I do also have a #!/bin/bash shebang in start.sh

cron isnt easy to use when your calling things that may depend on environment variables and other similar things (since these are not available to cron). You have to set them in your script. This is why it works when you run it yourself but not when cron runs it.

However it sounds like you basically want to run a bot as a service, the best way to do this would be to create an init script for it.

This should work (i think)

in /etc/systemd/system/mumbledj.service

[Unit]
Description=Mumble Bot

[Service]
Type=oneshot
ExecStart=/opt/mumbledj/start/sh

[Install]
WantedBy=multi-user.target

Then systemctl enable mumbledj.service this will set it to start automatically at boot.

Are environment variables set up prior to rc.local because the script runs fine from there?

Off the top of my head I cant remember. It hooks in at a shell, cron doesnt run with one so doesnt have access to environment variables. You'd need to set them inside the script i think. However an init script would definitely be the better option I think for this as you have much better access to whats going on with it, not to mention the ability to hoot in start/stop/restart options, wait for network or other, etc.

Alright. That's what I'll do.