crontab-ui icon indicating copy to clipboard operation
crontab-ui copied to clipboard

ENVS are not set

Open isgroup opened this issue 2 years ago • 8 comments

The "Environment Variables:" box seems to be non functional on the latest docker image. Variables are not set and inaccessible by jobs.

Regardless of the format inputted in such box, eg:

KEY=value

Or the "wrong" for a crontab file format:

export KEY=value

When executing a simple job like the command "env", the variables are not set. Both when manually executed by the UI or automatically executed by the cron daemon.

I inspected the docker image with crontab -e and the source code and everything seems correct (https://github.com/alseambusher/crontab-ui/blob/6cf4ce4eb818d485a22b24b0e2afabb1f81eb77a/crontab.js#L92).

Does anybody else has the same behavior?

Maybe I'm missing something obvious.

Thanks, Francesco

Make sure these boxes are checked( - [x] ) before submitting an issue.

  • [X] Gone through existing open and closed issues.
  • [X] Running latest npm and node? (Run npm --version and node --version). Get the latest nodejs here.
  • [X] The node_modules folder has right permissions (Run ls -ld $(npm root -g)/crontab-ui)
  • [X] Read issues.md

isgroup avatar Dec 30 '21 16:12 isgroup

Did you click on "save to crontab"?

alseambusher avatar Dec 30 '21 18:12 alseambusher

@alseambusher yes sure and I checked with crontab -e in an interactive shell that the crontab has been updated (it was). Thanks!

isgroup avatar Dec 30 '21 18:12 isgroup

For example:

Screenshot at 2021-12-30 19-07-50

No "foo" variable in the log.

isgroup avatar Dec 30 '21 18:12 isgroup

They are not visible to env but they exist locally. IMHO it's something related to the Busybox crond. If a value contains a "&" the parse fails and none of the envs are available as local variables.

Solution: Double quote the value, eg.:

FOO="https://xxx.ch/xxx/xxx?xxx&xxx"

isgroup avatar Dec 30 '21 18:12 isgroup

Very weird, the above solution is partial as a script (for example a PHP script) will not be able to access the data using getenv(). I discovered that a single line at the beginning of the envs:

export FOO=bar

Somehow refresh all the envs and now env sees everything.

Solution: Add a dummy export FOO=bar line at the beginning.

isgroup avatar Dec 30 '21 18:12 isgroup

Bummer. The above works only when manually executing the task. Jobs executed automatically do not have any of the envs, regardless the export command.

isgroup avatar Dec 30 '21 18:12 isgroup

Bummer. The above works only when manually executing the task. Jobs executed automatically do not have any of the envs, regardless the export command.

See the Dockerfile of this project. There you can see it uses Alpine Linux as base. Alpine Linux uses BusyBox cron (whilst e.g. Debian uses Vixie cron). As explained here, the ability to declare variables at the top of crontab files differ per implementation. BusyBox does not support it. This is a problem, since the variables as defined in crontab-ui will be added to the top of the actual crontab file, which is thus not supported in this configuration.

A solution would be therefore to change the Dockerfile to use Debian or Ubuntu as base image. Note that this leads to other mandatory modifications, like changing apk to apt in the Dockerfile.

Looks like the original developer of this project didn't know these specifics and/or did not test it well. The fact that it does work when you manually run a job lies in the fact that cron is not involved in that case. Under the hood it'll just instantly declare the variables in a command and then run the given command in the same shell.

jaspervann avatar Jun 03 '22 20:06 jaspervann

I've got a better solution than changing the base image. Why not just fix it by modifying crontab-ui's code?

In https://github.com/alseambusher/crontab-ui/blob/master/crontab.js change line 183 from crontab_string += make_command(tab) to crontab_string += add_env_vars(exports.get_env(), make_command(tab)), then remove line 175 up and until 178.

This will result in the crontab file not having the top lines defining variables (which is not working in BusyBox), but rather embedding the variables into the commands to be executed themselves, just like how it is done when executing a job manually.

jaspervann avatar Jun 03 '22 22:06 jaspervann

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 01 '22 15:09 stale[bot]