Can Jenkins monitor cron jobs that I run using crontab? - cron

I have written some cron jobs using the crontab feature on my ubuntu. Can I use Jenkins to monitor these jobs?
Edit 1: I have Jenkins already installed on my local machine: localhost:8080. So right now, I have cronjobs running on crontab. I cannot create a new job on Jenkins and run them on Jenkins's shell because of certain requirements.
Following Pragmatic's solution, I looked at https://wiki.jenkins-ci.org/display/JENKINS/Monitoring+external+jobs and tried to sudo apt-get install jenkins-external-tool-monitor, but I am getting: E: Couldn't find package jenkins-external-tool-monitor. Any work arounds?
Edit 2: I have figured it out. Very Important: I tried to set this up using jenkins-core-1.47*.jar file, and it didnt work. It did work with jenkins-core-1.466.jar. So if you are using some .jar file, stop jenkins, replace it with a jenkins.war that corresponds to jenkins-core-1.466.jar and start jenkins after. That should work!

Yes, you can do that!!
Have a look at this link: Monitoring external jobs.
I could have explained the whole method here itself but the details in the question were minimal.
Hope this helps you.

Possible...See this
https://wiki.jenkins-ci.org/display/JENKINS/Monitoring+external+jobs

As others have stated above, follow: https://wiki.jenkins-ci.org/display/JENKINS/Monitoring+external+jobs
Then I started getting this ugly error: https://issues.jenkins-ci.org/browse/JENKINS-14107
If you face this problem as well, replace the current jenkins.war file with one from version 1.466. That is the one that worked for me. Before I replaced the war file, I stopped the jenkins server by : /etc/init.d/jenkins -stop and then replaced the war file and then started the server: /etc/init.d/jenkins -start

An alternative approach is to use an instance of Jenkins to replace your cron jobs entirely.
See:
Drop that cron; use Hudson instead
Replace Local Cron With Jenkins

Related

Make chosen version of Elasticsearch run as a service in Linux

I have an issue with later versions of ES, so have to use 7.10.2 currently.
This means that the previous method I used to install ES as a service, i.e. apt-get, doesn't work You can't choose an older version this way: it currently installs 7.16.3.
So I followed the procedure on this page for 7.10: everything worked: I was able to run ES as an app and also as a "daemon". Clearly I could simply put the "daemon" startup line in a script which runs on boot.
But what's the optimum way of turning this "daemon arrangement" into a service which you can control with systemctl, and which starts automatically when the machine boots?
PS I don't want to get involved with Docker. I'm sure that's a useful thing but I'm convinced there is a simpler way of doing it, using available Linux sys tools.
I found a workaround... this doesn't in fact create a service of the "systemd" type which can be controlled by systemctl. There seem to be one or two problems which make this non-trivial.
1) You can't start ES as root! I assume (not sure) that most services are being run by root. Anyway this was something I couldn't find a solution to.
2) I am not sure whether a shell script file called by a service is allowed to end... or should continue endlessly: initially I thought this would be sufficient. This is a shell script (run_es_daemon.sh) which does indeed start up ES (as a daemon process) when run by manually in a terminal. There is no issue to do with the fact that the script ends and you then close the terminal: the daemon process continues to run:
#!/bin/bash
# start ES as a daemon...
cd /home/mike/Elasticsearch/elasticsearch-7.10.2
./bin/elasticsearch -d -p pid
... but it never worked using a xxx.service file in /etc/systemd/system/ (maybe because of 1) above). So I also tried adding these lines under the above ones:
while true
do
echo "bubbles"
sleep 60
done
... didn't work either.
In the end I found a simple workaround solution was to start up the daemon process by using crontab:
#reboot /home/mike/sysadmin/run_es_daemon.sh
... but I'd still like to know how to set it up as a true service, which starts at boot...

Raspberry Pi boot script duplicating

I am trying to run a few scripts at each boot of the raspberry pi. I have been able to verify that when they are not configured to start automatically, I can run them, and they all work exactly as intended (and in only one instance). I have tried quite a few methods of autostarting these scripts, and I have found that using a desktop entry in .config/autostart directory to be my preferred way of doing it. I have also tried editing rc.local, crontab, systemd, and entries in .config/lxsession/LXDE-pi/autostart with no more success.
The issue is that when I have the scripts running at boot, there is a duplicate of the script running (I have it set to open a new instance of LXterminal, though there are not duplicates of the terminal). The script runs at boot just fine, but I am cannot figure out why there seems to be a "ghost" version of the script too. I have the autostart commands set to write to log files that show that the scripts are running more than once. I have also tried this on a fresh raspbian install. Could someone help me figure this out? I'm at a loss on what my issue is. This is for use of Amazon Alexa.
This is what I have in /home/pi/.config/autostart/AlexaBoot.desktop:
[Desktop Entry]
Name=AlexaBoot
Exec=lxterminal -e "/bin/bash /home/pi/Desktop/alexa_boot.sh"
Type=Application
I can post what I have in the autostarted script if necessary. Thanks.
Found a fix for this. My solution is outlined on a similar Github issue, hopefully this is able to help someone with the same issue.

nodejs app with forever in cronjob does not work after reboot

I created a cronjob with sudo crontab -u USERNAME -e and tried to start my node.js app after each reboot.
It had worked well at another server.
But this time, I installed the Node.js via nvm
Then tried to run the same cronjob lines, but every time after reboot it failed. I tried to figure out all the related folders and tried again to run as different lines. When I check with forever list, server shows that no process is running.
#reboot /home/USERNAME/.npm/forever start -c /home/USERNAME/.nvm/current/bin/node /home/USERNAME/APPNAME/app
#reboot /home/USERNAME/.npm/forever start /home/USERNAME/APPNAME/app
#reboot /usr/local/bin/forever start -c /home/USERNAME/.nvm/current/bin/node /home/USERNAME/APPNAME/app
I think that the reason is somehow related with nvm. But I am not sure of that. I don't want to do anything unnecessary unless I am fully sure about it.
Edited July 26, 2015
Though I have used the npm's forever module to deploy nodejs production apps, I really do not see the need to use it on linux based servers as there are so many system level alternatives available.
One of them is upstart. It will help you run your scripts as system level services. Amazon Web Services also use upstart in their Elastic Beanstalk nodejs tiers to keep nodejs apps running forever.
If you really just need to get down to it, here is a link to run your nodejs app as an upstart service.
However, it is not limited to deploying nodejs apps only and if you learn upstart, you will be able to do a lot of things with it. Here is a link for that as well.
If your original approach was preferable (as it was in my case) you can fix your scheduled cron job by explicitly passing the path to node like this: (found in this answer)
#reboot /root/.nvm/versions/node/v7.1.0/bin/node /root/.nvm/versions/node/v7.1.0/bin/forever start /var/www/server.json
Apparently NVM works in magic by setting up some system paths which aren't setup at the moment the cron jobs run.

how to run npm/grunt command from jenkins

I'm new to this area and was trying to run the following commands from jenkins:
npm install
grunt quickStart
So far I've a jenkins running on a window machine as a window service and I've also installed NodeJs plugin for jenkins.
However, I'm stuck and quit confused following instructions here, its asking me to to add one or mode nodeJs installation and I could not find those setting and not even sure if I even need them in the first place.
Here is the bit that's asking me to do:
I cannot see this setting for the jenkins job I create. Is there an easy way to run those command in jenkins from a .bat or .sh script, a .bat would be recomended since I'm on window machine.
Note : I've already checked out a project using git in jenkins!!!
Thanks
"its asking me to to add one or mode nodeJs installation and I could not find those setting and not even sure if I even need them in the first place."
I don't think you need that I have pointed jenkins to the node installation folder an nothing more.., for this you go to Manage Jenkins->Configure System->NodeJS->NodeJS installations.. type in any name you like and point to where the node home folder is.
...cannot see this setting for the jenkins job I create...
Once you have configure that in your jenkins configuration you should have that configuration available like so:
...Is there an easy way to run those command in jenkins from a .bat or .sh script, a .bat would be recomended since I'm on window machine
I'm sorry don't get what commands are you referring to...
so summarizing :
you have to tell jenkins where you have your node installation
use that configuration in your jobs
hope this helps...
The way I made it, was trough execute shell, as the build tool for nodejs is npm, I simply wrote a shell script that instructs jenkins to run npm install in the workspace directory inside jenkins where it clones the git repository and then to zip and move the package if successful to another folder.

install script to run then reboot and continue

I have a script that is a pre installation script for a specific piece of software. the script takes care of a lot of the pre-requisites of the installation as well as kernel configuration.
What I am trying to do is create a set of scripts that automates the entire installation of this software and what I would like to know is if there is a way to have a script reboot the box and then ONE TIME kick off the second script that will execute the post reboot commands automatically to complete the installation.
I have several boxes I need to run this on (in excess of 40-50) and would really appreciate a way to do such a task where i can run the first script and have it take care of the reboot and completion of install.
Any ideas?
A solution is to add the script path in /etc/rc.local, that way, the script will be ran #reboot

Resources