linux的服务开机设置一般在 /etc/init.d/里

而jexus的默认安装目录在 /usr/jexus里 启动文件为 jws 参数 有start stop restart

jexus的开启启动脚本

1
#!/bin/bash
2
### BEGIN INIT INFO
3
#
4
# Provides:  jws
5
# Required-Start:   $local_fs  $remote_fs
6
# Required-Stop:    $local_fs  $remote_fs
7
# Default-Start:    2 3 4 5
8
# Default-Stop:     0 1 6
9
# Short-Description:    jws
10
# Description:  This file should be used to construct scripts to be placed in /etc/init.d.
11
#
12
### END INIT INFO
13
14
## Fill in name of program here.
15
PROG="jws"
16
PROG_PATH="/usr/jexus" ## Not need, but sometimes helpful (if $PROG resides in /opt for example).
17
PROG_ARGS="start" 
18
PID_PATH="/var/run/"
19
20
start() {
21
    if [ -e "$PID_PATH/$PROG.pid" ]; then
22
        ## Program is running, exit with error.
23
        echo "Error! $PROG is currently running!" 1>&2
24
        exit 1
25
    else
26
        ## Change from /dev/null to something like /var/log/$PROG if you want to save output.
27
        $PROG_PATH/$PROG $PROG_ARGS 2>&1 >/var/log/$PROG &
28
    $pid=`ps ax | grep -i 'jws' | sed 's/^\([0-9]\{1,\}\).*/\1/g' | head -n 1`
29
30
        echo "$PROG started"
31
        echo $pid > "$PID_PATH/$PROG.pid"
32
    fi
33
}
34
35
stop() {
36
    echo "begin stop"
37
    if [ -e "$PID_PATH/$PROG.pid" ]; then
38
        ## Program is running, so stop it
39
    pid=`ps ax | grep -i 'jws' | sed 's/^\([0-9]\{1,\}\).*/\1/g' | head -n 1`
40
    kill $pid
41
        
42
        rm -f  "$PID_PATH/$PROG.pid"
43
        echo "$PROG stopped"
44
    else
45
        ## Program is not running, exit with error.
46
        echo "Error! $PROG not started!" 1>&2
47
        exit 1
48
    fi
49
}
50
51
## Check to see if we are running as root first.
52
## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html
53
if [ "$(id -u)" != "0" ]; then
54
    echo "This script must be run as root" 1>&2
55
    exit 1
56
fi
57
58
case "$1" in
59
    start)
60
        start
61
        exit 0
62
    ;;
63
    stop)
64
        stop
65
        exit 0
66
    ;;
67
    restart)
68
        stop
69
        start
70
        exit 0
71
    ;;
72
    **)
73
        echo "Usage: $0 {start|stop|restart}" 1>&2
74
        exit 1
75
    ;;
76
esac

增加文件权限

1
sudo chmod +x /etc/init.d/jws

添加自动启动服务

1
sudo update-rc.d jws defaults

删除自动启动服务

1
sudo update-rc.d jws remove