I've a cron job that is supposed to execute a ruby script but it is failing with:
/bin/sh: 1: jruby: not found
I know I can set manually jruby location but I want cron to pick automatically as this will be deployed in different machines which have different paths of jruby locations.
Any ideas how to achieve this?
I think env is your friend.
Assuming JRuby isn't installed in multiple locations on a given box, /usr/bin/env jruby is a more portable means of having the system pick the first jruby instance it finds on the path.
Just make sure the JRuby is actually installed somewhere on the root users' PATH (or whatever user the jruby command runs as).
Related
I administrate a jenkins instance on Linux.
I have been asked to pass a system-wide JAVA_HOME as a global ENV var for jenkins builds (as opposed to just jenkins itself), and I wish to do this through the service/daemon startup script. (Please don't give per-job Jenkinsfile / build pipeline solutions.)
Some plugins like maven-javadoc-plugin apparently require this variable.
(Curiously, this was never before necessary for the existing builds on this jenkins install. Either the used plugins changed, or jenkins did? Since I don't build on this, I can't say which.)
The only way I managed to do make this work for now, is using a fixed string through the GUI at <jenkins-url>/configure under "Global properties > Environment variables".
I understand I can add JDK installations under <jenkins-url>/configureTools/, but this, again, only allows fixed strings, which I can't be bothered to remember correcting on every system update.
What I should be able to do instead, is pass the ENV var to the jenkins service at startup, such as: JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java)))).
jenkins (debian package) in fact brings an /etc/default/jenkins file,
which says you can pass a --javahome=$JAVA_HOME argument; like this:
/usr/bin/java -jar jenkins.war --javahome=/usr/lib/jvm/java-11-openjdk-amd64
However, this seems incorrect and does not work on current jenkins versions. It throws java.lang.IllegalArgumentException: Unrecognized option: --javahome=/usr/lib/jvm/java-11-openjdk-amd64 at winstone.cmdline.CmdLineParser.parse(CmdLineParser.java:52)
Since some other options uses camelCase (like --httpPort), I have also tried --javaHome=$JAVA_HOME instead.
This option is accepted (jenkins doesn't choke on startup), but it also doesn't work, it appears to get ignored?
I didn't manage to figure out if this should be the correct option from the source code either.
Jenkins version: 2.319
Perhaps someone can tell me if this used to work, is a bug, or how to do this if I'm doing it wrong.
This question already has answers here:
How to get CRON to call in the correct PATHs
(15 answers)
Closed 4 years ago.
I am porting from SuseLinux to CentOS
Default Path Variable of cronjob in Suse Linux was - PATH=/usr/bin:/bin
All the Application Scripts worked fine in Suse Linux.
Now in CentOS, many binaries have been moved to /usr/sbin directories.
Now when these application scripts are run from cron job in CentOS they do not work because cron job default PATH in Centos is also PATH=/usr/bin:/bin. So these Cron scripts cannot access binaries present in /sbin or /usr/sbin directories.
Have to make PATH variable like PATH=/usr/bin:/bin:/usr/sbin
So that all my application scripts work.
I don't want to change Application Scripts and give the full path to all the binaries in these scripts. As it would produce many changes.
Setting PATH variable on top of Cron Script when the application installs and removing it when the application uninstalls, and even making changes during application upgrade also seems a lot of work.
I wanted to know the optimal or less work solution
It would be better if the change involves is in application side and I don't have to make changes in OS rpm.
Centos is based on Redhat Enterprise Linux which makes use of vixie-cron. This allows you to change the path in the crontab file.
PATH=/usr:/usr/bin:/path/to/something/else
1 2 * * * command
More Information:
Centos 5.2 Manual
Redhat Enterprise Linux Manual
How to get CRON to call in the correct PATHs
Why is my crontab not working, and how can I troubleshoot it?
I try to execute a java application at startup in a yocto based linux device. I added a script at /etc/init.d/etic and made it executable. If I call at the shell /etc/init.d/etic start or /etc/init.d/etic stop the application is started an stopped as expected. Then I called on the shell update-rc.d etic defaults and the symlinks were created. According to what I found on the web, this should be enough, but somehow the application is not started. What did I miss? How could I check what is going wrong or is there any minimal example which should work which I can try to extend?
Well, often such issues are due to a different environment when executing the start script by hand, as compared to when it's being run from the init system. For instance, your .profile and .bashrc won't have been sourced, when running from the init system.
You can use eg logger to easily log things from your init-script, and this rather easily find out what goes wrong.
On an OpenSuSE linux machine, I want to run a script when the machine is booted. As the script does not start a service, is /etc/rc.d the correct place for the script?
Thanks.
That's where I've always put them. There are several scripts in rc.d already which don't actually start a process. However, you need to write it in a similar fashion to the other startup scripts - have a look at a few to see how they are set up. Specifically, you should make sure that it's possible to run the script using /etc/rc.d/myscript start.
I am sure this has to be out there somewhere, but after about a day of searching I am stuck. I am trying to use IZPack to do an installation on Linux and trying to call a shell script that sets some environment variables. However I don't know how to "source" the script instead of just running it. Running the script using:
<executable type="bin" stage="postinstall" targetfile="$INSTALL_PATH/myscript.sh" os="unix"/>
This only executes the script, it does not source it. So all exports of ENV variables are lost once the script completes.
How can I source my scripts from IZPack instead of just running them?
IMHO you simply cannot influence the shell environment your Java process of your IzPack installer is running in from that process itself.
Torsten is right. This is not an issue of IzPack, Java or anything else, this is just the way operating system process work with respect to environment variables ;-)