I am programming some schedule task in my Ubuntu 16.04.
But when I try to start the crond.service by
sudo service crond start
I receive the message
crond.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
What's the problem? The tasks was added to the schedule by crontab command and look fine (the command works in the terminal, have the correct tree folder, I just added the day-hours parameters).
It's because the service name on 16.04 is cron, not crond. So your command should be:
sudo service cron start
You can verify on your server by looking in the /etc/init.d folder. All the services are there.
ls -l /etc/init.d
Related
Hi im trying to setup a cron job to restart a game server daily but its failing to work
i have used crontab -e to install a job
* 3 * * * systemctl --user restart <servicename>
this failed to restart my process at 3 am as expected.
i also tried moving the command to a bash file and running the bash file through cron (as i have seen alot of people use .sh files to run commands)
additionally i have tried installing to job as root with zero success
this had similar results
my syslog did show a command execute as expected yesterday though the service didnt restart, since then cron isnt showing any new attempts.
i found some info on troubleshooting and following the guidance shows that my cron is working, i managed write the date/time to a file every minute and the service is clearly running and this showed in the logs.
is there a problem with cron running systemctl commands or is there further steps i can use to see why its failing?
Edit:
i tried running my command as root also and nothing happened
Jan 31 09:00:01 ns509515 CRON[108307]: (root) CMD (<user> systemctl --user restart EcoServer)
Jan 31 09:01:01 ns509515 CRON[108330]: (root) CMD (<user> systemctl --user restart EcoServer)
Jan 31 09:02:01 ns509515 CRON[108356]: (root) CMD (<user> systemctl --user restart EcoServer)
So today one of our application servers were restarted due to some issue and after restart we found that our application services were not running.
I want to create one script which will check these below services after a server restart and start them automatically if found stopped:
1st Service with Path : /opt/bea/config/nm/nm-sdi-abc/beaNMctl.sh
2nd service TOMCAT - Path : /opt/apache/tomcat/bin --- Service name startup.sh
Catch here is 1st service can be started with the normal id account that i use.
But 2nd service can be restarted after logging into a different service account on same server and network. Like below:
[x201691#abc bin]$ su - apache
Password:
-bash-2.05b$ cd /
-bash-2.05b$ cd /opt/apache/tomcat/bin/
-bash-2.05b$ ./startup.sh
Can someone help?
Also we are not root users.
You can write a shell script:
echo YOUR_PASSWORD | sudo -S su
cd /opt/apache/tomcat/bin/
./startup.sh
Save this as a file somewhere you have access and add the following cron entry:
#reboot MYPATH/myscript.sh >> MYPATH/script.log 2>&1
script.log will contain any output or errors from your script. You can add date command to the script to help with information on when it was run. More information on cron here.
Also, if you have concern with putting password in the script, you can go through the discussion here.
Preferred approach when installing Tomcat in Linux is to make Tomcat as a service.
This will ensure your service is started after reboot
1. Create the service file with the following command:
touch /etc/systemd/system/tomcat.service
2. Assign the relevant rights to the file you created:
chmod 664 /etc/systemd/system/tomcat.service
3. Paste the following content in the file while adapting it to your configuration:
[Unit]
Description=Application description/name
After=syslog.target network.target
[Service]
Type=forking
User=tomcat
ExecStart=$CATALINA_HOME/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID
Install]
WantedBy=multi-user.target
4. Reload the service daemon:
systemctl daemon-reload
5. Start the service:
systemctl start tomcat
6. To check status :
systemctl status tomcat
I have a Ubuntu 16.04 LTS machine where I am successfully connected to the Jenkins server via JNLP connection. Steps I took for the connection are the following:
Create a directory in the slave called /home/MyUbuntu/Jenkins
Download both agent.jar and slave-agent.jnlp files into the
directory
Run this command from the terminal:
java -jar agent.jar -jnlpUrl http://my-jenkins-server:8080/computer/MyNode/slave-agent.jnlp -secret 6f8bb3250d6dbcda77979797997b0ea6bcaaa064785d558c0e4ea07d03 -workDir "/home/MyUbuntu/Jenkins"
The connection is successful.
Problem:
Once I close the terminal the connection gets disconnected.
Question:
How do I add this as a service in Ubuntu 16.04 LTS so whenever the machine is rebooted it starts as a startup???
If you use System D, add a file like this to /etc/systemd/system/.
[Unit]
Description=Jenkins slave connection
Wants=network.target
After=network.target
[Service]
ExecStart=java -jar agent.jar -jnlpUrl http://jenkinsurl:port/endpoint.jnlp -secret 4lph4num3r1cs3cr3t -workDir "/base/path/of/your/jenkinsjar"
Restart=always
WorkingDirectory=/base/path/of/your/jenkinsjar
User=my-user
Group=my-group
RestartSec=20s
[Install]
WantedBy=multi-user.target
Alias=jenkins.service
Permissions and ownership of the file may vary based on the service or OS. Long list files in /lib/systemd/system/ to get an idea of what perms you need or want (probably root:root 644).
Notice the command is the command that Jenkins provides for you when you create an agent jar. Just use that for ExecStart.
For user and group, I use the user that owns the directory where the Jenkins workspace is located. For example, if the Jenkins workspace is in /home/ubuntu, I specify ubuntu as user and group.
After that...
Prefix these with sudo if you're not running as root:
Probably a good idea to reload System D: systemctl daemon-reload.
Start: systemctl start jenkins.service. Notice this command pertains to the last line of the file Alias.
Enable it if you want the service to start with your computer: systemctl enable jenkins.service.
Here are the Git Gists I based my file on:
https://gist.github.com/unakatsuo/d4711f52a0ab0b9bc8010018149a7e84
https://gist.github.com/dragolabs/05dfe1c0899221ce51204dbfe7feecbb
I'm sure there's a lot more that can be done for the service config but in my case, I manage a lot of different servers and just need the thing to start automatically after boot!
So I created a service and made it executale in /etc/init.d
Then I tried to make it start after boot with the following command:
update-rc.d <myService> defaults
But the output were warnings of other services (which work just fine by the way) and I don't want to touch those.
My next attempt to solve this was to add the following lines in the rc.local file:
do_start() {
service <someOtherService> stop
service <myService> stop
sleep 5
service <someOtherService> start
service <myService> stop
........
As I said, I have some other service that works just fine, but my service which I am currently trying to add wont start after boot.
One more thing that I would like to add is when I manually enter:
service <myService> start/stop
then it works just fine
To add a service at boot, you can add an Upstart job.
Create your conf file in /etc/init (e.g. /etc/init/myjob.conf)
with a content like this (Example)
description "My job"
start on startup
task
exec /path/to/script.sh
More informations here (Debian doc)
Info: you need the upstart package.
The following works very well for me.
First determine if your system is running SysV init or systemd, for that use:
$ ps -p 1
If SysV init:
$ sudo update-rc.d <service_name> defaults 95 10
If systemd:
$ sudo /bin/systemctl daemon-reload
$ sudo /bin/systemctl enable <service_name>.service
I successfully used the last one on a ParrotSecurity OS that is based on Debian 5.
I am using Jessie. Cron was working fine last week. But I just checked today and found out, it's not working anymore. When I restart upstart loads my custom tasks. But if I check
sudo service --status-all
Cron is shown marked as [ - ] cron
When I execute sudo service --status-all, I get [FAIL] cron is not running ... failed! in return. Manually starting cron service executes the tasks in crontab. But, the service is not starting on boot.
There is no problem with crontab task specification. They are working fine on my other machines running Ubuntu.