Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to get a .jar file to run at startup on an Ubuntu machine, but I'm not getting anywhere. I've tried the instructions here http://askubuntu.com/questions/99232/how-to-make-a-jar-file-run-on-startup-and-when-you-log-out , and I've tried using info from the Upstart site & cookbook, but they haven't worked. I've tried both the old SysV and the new Upstart approaches, but neither of them start the .jar on system startup.

Here is the shell script which runs the .jar

#!/bin/bash

java -jar TransformationServer.jar

The file for the SysV startup approach

#!/bin/bash
# Transformation Server
# 
# Description: Transforms incoming messages on a given port and forwards them

case $1 in
    start)
        /bin/bash /usr/local/bin/ServerStart.sh
    ;;
    stop)
        /bin/bash /usr/local/bin/ServerStop.sh
    ;;
    restart)
        /bin/bash /usr/local/bin/ServerStop.sh
        /bin/bash /usr/local/bin/ServerStart.sh
    ;;
esac
exit 0

UpStart approach

# transformationserver - transforms incoming http messages, and redirects them
#
# This service intercepts incoming http messages on a given port, and
# transforms them into an acceptable format in order to be received
# by a 3rd party service

start on runlevel [345]
stop on runlevel [!2345]

respawn

script
    exec /bin/bash /home/ubuntu/TransformationServer/ServerStart.sh
    # Also trying the below as well
    #exec /bin/java -jar /home/ubuntu/TransformationServer/TransformationServer.jar
end-script

Can someone with more experience in using either of these approaches look over my files here, and potentially point me in the right direction with this? This service is needed so our companies system can successfully receive communications from one of our clients.

Thanks in advance.

share|improve this question

1 Answer 1

How about you use the crontab?

As the user you want the jar to run as, run this:

crontab -e

Add the line:

@reboot /path/to/your/ServerStart.sh

Save it. That will make it so when the server comes back up after a reboot, it will run your shell script.

This is your crontab, you can learn all about it with man crontab, or the Wikipedia page: https://en.wikipedia.org/wiki/Cron

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.