Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Variable when Running As User #125

Open
AlexAbraham1 opened this issue Oct 9, 2018 · 1 comment
Open

Environment Variable when Running As User #125

AlexAbraham1 opened this issue Oct 9, 2018 · 1 comment

Comments

@AlexAbraham1
Copy link

Summary

I tried running the shell script plugin as user service. When running the first command in my shell script source activate anaconda_env_name it fails because it can't find source. However, if I start the shell script with PATH=/data/anaconda/envs/anaconda_env_name/bin:$PATH it works.

Is there a way to use all environment variables of the user running the job instead of the root user?

Thanks!

Steps to reproduce the problem

  1. Modify shell script plugin to run as user X
  2. Create job which relies on environment variable set for user X but not for root user
  3. Run job

Your Setup

Ubuntu server running cronicle as master and ubuntu server as slave running job

Operating system and version?

Ubuntu 16

Node.js version?

10.10.0

Cronicle software version?

0.8.28

Are you using a multi-server setup, or just a single server?

Single Server

Are you using the filesystem as back-end storage, or S3/Couchbase?

File system

Can you reproduce the crash consistently?

Yes

@jhuckaby
Copy link
Owner

Thanks for the issue report. I don't think there is a good way to load all the environment variables for a given user, and have it work across operating systems and shells. As I understand it they all do it differently (~/.profile and ~/.bash_profile come to mind). I think there are other places the user's environment variables can be stored as well. Actually "logging in" a user as one would in a Terminal is not something Cronicle can actually do (I'm not even sure how to do it). It just changes the permissions so it can execute scripts and write files as that target user.

Here are some things you can do. First, if you want to globally set that PATH for all your events, you can do it in your main Cronicle configuration file. Just set the job_env configuration property, and include your PATH in there. Example:

"job_env": {
	"PATH": "/data/anaconda/envs/anaconda_env_name/bin:/bin:/usr/bin"
},

Unfortunately this method doesn't expand inline variables, so you can't prepend or append to the existing $PATH. You'll have to explicitly specify all the paths like /usr/bin etc.

Another thing you can do is try to execute the user's ~/.profile file (or wherever this exists in your OS and your shell). I believe you can do this by placing this command at the top of your shell script (under the Shebang line):

#!/bin/bash
source ~/.profile

# Your shell script here

Note that I have no idea which OSes or shells support this file. I seem to recall in some cases I've seen it called ~/.bash_profile instead. This file may include the target user's PATH additions, but again, I really have no idea. I am sort of grasping at straws here.

Good luck, and sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants