我试图让一个.jar文件在Ubuntu机器启动时运行,但我没有得到任何地方。 我试过这里的说明https://askubuntu.com/questions/99232/how-to-make-a-jar-file-run-on-startup-and-when-you-log-out ,已经尝试使用Upstart网站和食谱的信息,但他们没有工作。 我已经尝试了旧的SysV和新的Upstart方法,但是他们都没有在系统启动时启动.jar。
这是运行.jar的shell脚本
#!/bin/bash cd /home/dev/TransformationService/ java -jar TransformationServer.jar
SysV启动方法的文件
#!/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方法
# 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
可以有更多的经验,使用这些方法的任何一个在这里查看我的文件,并有可能指向我在这个正确的方向吗? 这项服务是必要的,所以我们的公司系统可以成功地接收我们的客户之一的通信。
提前致谢。
你如何使用crontab?
作为你想让jar运行的用户,运行这个:
crontab -e
添加行:
@reboot /path/to/your/serverStart.sh
保存。 这将使得当服务器重新启动后恢复时,它会运行你的shell脚本。
这是您的crontab,您可以通过man crontab或Wikipedia页面了解所有相关信息: https : //en.wikipedia.org/wiki/Cron