views:

1306

answers:

4

At the moment I have to go to /usr/java/apache-solr-1.4.0/example and then java -jar start.jar

Any ideas how to get this to start automatically on boot?

Im on a shared linux server.

Cheers

A: 

Check man 5 crontab See if @reboot is supported on the linux you are using

gnibbler
+5  A: 
SuperMagic
I am admin, I get `service solr does not support chkconfig` when running `chkconfig --add solr`, what does the startup script need to be called? just solr? no extension?
bluedaniel
You can call the script in /etc/init.d whatever you like. If chkconfig isn't playing nice, make the links manually (the ln -s commands). That's really all chkconfig does... just provides a nice tool to do it for you. Ah... also make sure the solr script in init.d is executable: chmod +x /etc/init.d/solr (or whatever you called it)
SuperMagic
no dice, `Starting solr: /bin/bash: java: command not found` error when `% /etc/init.d/solr start` and it does not run on boot still
bluedaniel
It looks as if the script needs to invoke java with its absolute path.
rleir
which part of the script needs changing to reflect that?
bluedaniel
If you're on ubuntu: update-rc.d solr defaults
Till
It's probably `/usr/bin/java`, not `/usr/java`. Do `whereis java` on your system and find out.
Till
+4  A: 

First, find out where java is located on your machine. The command below will tell you where it is:

$ which java

Then, stick the following code into a shell script, replacing the java path below (/usr/bin) with the path you got from the above command.

#!/bin/bash

cd /usr/java/apache-solr-1.4.0/example
/usr/bin/java -jar start.jar

You can save this script in some location (e.g., $HOME) as start.sh. Give it world execute permission (to simplify) by running the following command:

$ chmod og+x start.sh

Now, test the script and ensure that it works correctly from the command line.

$ ./start.sh

If all works well, you need to add it to one of your machine's startup scripts. The simplest way to do this is to add the following line to the end of /etc/rc.local.

# ... snip contents of rc.local ...
# Start Solr upon boot.
/home/somedir/start.sh

Alternatively, if you don't have permission to edit rc.local, then you can add it to your user crontab as so. First type the following on the commandline:

$ crontab -e

This will bring up an editor. Add the following line to it:

@reboot /home/somedir/start.sh

If your Linux system supports it (which it usually does), this will ensure that your script is run upon startup.

If I don't have any typos above, it should work out well for you. Let me know how it goes.

0xfe
Success!!! Thanks so much you have no idea
bluedaniel
A: 

Follow supermagic's comments, then follow this

http://codingrecipes.com/service-x-does-not-support-chkconfig

He says,

1 – Copy your script into /etc/init.d folder
2 – cd /etc/init.d
3 – chmod +x myscript
4 – Add these lines, including #, right after #!/bin/bash or #!/bin/sh:

# chkconfig: 2345 95 20
# description: Some description
# What your script does (not sure if this is necessary though)
# processname: myscript

Then you can do

chkconfig --add myscript

Visitor