简体   繁体   中英

How do you run a jar file on boot (Ubuntu 11.10)?

I'm using Ubuntu 11.10. I've written a simple listener application in Java which runs properly (tested). Basically this java application in a loop that waits for an event every 60 seconds. After successfully jar-ing this file, I'm able to execute the file using

/usr/bin/java -jar /home/testuser/MyApp.jar

What I want to do is a create a shell script that starts this application when Ubuntu boots. My autostart.sh script is really simple:

#!bin/bash
/usr/bin/java -jar /home/testuser/MyApp.jar

Then I use the following commands to put it in the init.d directory:

#: sudo cp /home/testuser/autostart.sh /etc/init.d
#: chmod 777 /etc/init.d/autostart.sh
#: sudo update-rc.d /etc/init.d/autostart.sh defaults

Then I restart and use top to see if Java is running, but I dont see this. Does anyone know what the best way to implement this?

Using "ls -l /etc/rc?.d/*autostart" I get:

@hovanessyan: my output for that command is -

lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc0.d/K20autostart -> ../init.d/autostart

lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc1.d/K20autostart -> ../init.d/autostart

lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc2.d/S20autostart -> ../init.d/autostart

lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc3.d/S20autostart -> ../init.d/autostart

lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc4.d/S20autostart -> ../init.d/autostart

lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc5.d/S20autostart -> ../init.d/autostart

lrwxrwxrwx 1 root root 17 2012-03-19 14:26 /etc/rc6.d/K20autostart -> ../init.d/autostart

Create an upstart job and set the appropriate run level(s). Look at the other jobs in /etc/init with the .conf extensions for examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM