#!/bin/sh
if [ -z "$STY" ]; then exec screen -dm -S push /bin/bash "$0"; fi
cd ~/server
java -jar push.jar
把以上源碼另存爲xxx.sh 並賦予可執行權限,然後寫入/etc/profile內,
便可實現使用screen在後臺執行java -jar push.jar的操作。
需要先安裝screen
啓動兩遍的坑,最後通過shell來解決
http://git.oschina.net/lgh06/codes/e29kh14t8py3baoivzjmq
20160727更新:最好的方法是用supervisord 並把supervisord自啓動。
參見:
http://unix.stackexchange.com/questions/162133/run-script-in-a-screen
https://en.wikipedia.org/wiki/Shebang_(Unix)
http://www.vpser.net/manage/screen.html
https://www.gnu.org/software/screen/
https://wiki.archlinux.org/index.php/GNU_Screen_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)
https://wiki.archlinux.org/index.php/GNU_Screen