[英]Run Jar file on Ubuntu at system startup
我正在嘗試在Ubuntu機器上啟動時運行.jar文件,但我沒有得到任何地方。 我試過這里的說明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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.