Reputation: 2664
I have a jar file that tracks system info and logs it every 24 hours. How can I make it so that if the system restarts or starts the jar file is started as well? I am running a linux server with CentOS 6.4.
Upvotes: 0
Views: 5934
Reputation: 1
In addition of other (valid) answers, you could consider adding a crontab entry with @reboot
.
The @reboot
syntax to crontab
is a "Vixie" extension, but that syntax is common on Linux.
This supposes that your Linux system has cron
which is very likely. In addition, it does not require superuser privilege. You have to run the crontab(1) command to set it up.
You may still want to have your java program a regular linux "service". See also this and that answers.
Upvotes: 2
Reputation: 2254
Take a look at the following link: https://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-boot-init-shutdown-run-boot.html Basically, you should just run your jar from the /etc/rc.d/rc.local script
Upvotes: 2
Reputation: 4239
The simplest way is to add
java -jar YourJarFile.jar
in
/etc/rc.d/rc.local
Note: Commands in the above file are run at startup (as root). Note that if you do this, your command will NOT respond to the usual service start/ stop commands.
Upvotes: 4