时隔两年最近再次折腾opensuse 的一些笔记 - opensuse linux java service shell

时隔两年最近再次折腾opensuse 的一些笔记 - opensuse linux java service shell

 

opensuse 一些常用命令:
    service xxx start/stop  运行或停止服务
    chkconfig xxx on/off    将服务加入启动,重启后永久生效
    ps -ef 查看所有当前进程
    kill PID 终止某个ID 的进程

修改权限,让普通用户具有 root 权限:
1)修改 /etc/passwd 将用户id 修改成 0

    如: hz:x:0:0; huangzhi;; /home/hz/bin/bash

2) 修改 /etc/sudoers 在其中追加:

     hz ALL=(ALL) ALL 

 

给自己的某个 jar 包做成 linux 服务,分三步:

1)编写jar 包运行脚本 youservice.sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin  
CONNECT_HOME=/usr/local/myproject
cd $CONNECT_HOME

java -server -jar $CONNECT_HOME/my-server-launcher.jar &

2)编写 /etc/init.d/youservice shell脚本

#!/bin/bash  
#  
# Description:  测试  youservice

#  
# Source function library  
 
    . /lib/lsb/init-functions  

# END INIT

    case "$1" in  
      start)  
         echo "Starting youservice server"  
         #重点注意是  >/dev/null 2>&1 , 这行命令导致终端不会输出信息。
         /bin/bash /usr/local/myproject/youservice.sh >/dev/null 2>&1   
         ;;  
      stop)  
         PID=`ps -ef | grep 'my-server-launcher.jar' | grep -v grep | awk '{print $2}'`  
         echo PID
         echo "Stopping youservice server"  
         if [ ! -z "$PID" ]; then  
        kill -15 $PID  
         fi  
         ;;  
      restart)  
         $0 stop  
         $0 start  
         ;;  
      dump)
     PID=`ps -ef | grep 'my-server-launcher.jar' | grep -v grep | awk '{print $2}'` 
         if [ ! -z "$PID" ]; then
         kill -3 $PID

         fi
         if [ $? -ne 0 ]
         then
            echo "Failed to dump youservice."
            exit 1
         else
            echo "Dumped youservice."
        fi
         ;;
      *)  
        echo "Usage: youservice { console | start | stop | restart | status | dump }"
    esac

 

3)执行 hkconfig youservice on   将服务加入启动

kconfig -a youservice on 

 

服务脚本修改后,最好执行一下 systemctl --system daemon-reload 可能是用来刷新的

posted @ 2013-08-23 20:56  chinacloudy  阅读(275)  评论(0编辑  收藏  举报