cd appDir
vim pack.sh
#!/bin/bash exe="appname" des="desDir" deplist=$(ldd $exe | awk '{if (match($3, "/")) {printf("%s "), $3}}') $echo $deplist cp $deplist $des
#!/bin/bash touch /etc/ld.so.conf.d/test.conf echo "path" >> /etc/ld.so.conf.d/test.conf ldconfig -v
cd appDir
vim app_install.sh
#!/bin/bash cd appDir appname=appName chmod +x $appname ./$appname
可选择如下几个阶段操作(任选其一)
vim /etc/rc.local
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will exit 0 on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. /bin/bash /appDir/app_install.sh >/var/app.log exit 0
创建服务脚本
vim /etc/init.d/appService
#!/bin/bash ### BEGIN INIT INFO # Default-Start: 0 2 3 4 5 # Short-Description: ### END INIT INFO SERVER_NAME=appName SERVER_DIR=appDir SERVER_ARGS="" BASE_DIR=$(dirname $0) PID=$(dirname $0)/$(basename $0 .sh) `source /etc/profile` status() { if [ -f $PID ] then echo "---Started, PID file: $(cat $PID) [$PID]---" else echo "---No PID file---" fi } start() { if [ -f $PID ] then `ldconfig -v` echo "start $SERVER_NAME" `cd /opt/tips` `nohup $SERVER_DIR/$SERVER_NAME >/root/log 2>&1 &` #$SERVER_DIR/$SERVER_NAME >/root/log 2>&1 echo "start $SERVER_NAME success!" else echo "--No PID file---" fi } stop() { if [ -f $PID ] then echo "stop $SERVER_NAME" kill -9 `ps -ef | grep -v grep | grep $SERVER_NAME | awk '{print $2}'` #kill -9 `cat $PID` #sleep 1 echo "stop $SERVER_NAME success!" else echo "---No PID file---" fi } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; *) echo "usage: $0 {start|stop|restart}" exit 0 ;; esac exit
创建软连接
– 设置服务开机自启(默认条件) :update-rc.d appServicce defaults
– 移除脚本:update-rc.d -f appService remove
update-rc.d [-n] [-f] name remove
update-rc.d [-n] name default [NN | SS KK]
,NN表示执行序号(0-99),SS表示启动时的执行序号,KK表示关机时的执行序号,SS、KK主要用于在脚本直接的执行顺序上有依赖关系的情况下。
– 手动设置
ln -s /etc/init.d/appService /etc/rcX.d/S99appService
ln -s /etc/init.d/appService /etc/rcX.d/K99appService
注意:
runlevel
appInstall.sh
sleep 3
等待3秒AppName.desktop
[Desktop Entry] Version=1.0.0 Name=TIPS Exec=AppPath/AppInstakk.sh Type=Application
chmod +x AppName.desktop
cp AppName.desktop /etc/xdg/autostart