```
#!/bin/bash
# /etc/init.d/MyShell
### BEGIN INIT INFO
# Provides: abc
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: ledblink initscript
# Description: This service is used to manage a led
### END INIT INFO
case "$1" in
start)
echo "update route"
route del default gw 172.16.22.254
route add default gw 172.16.22.254 metric 256
route add -net 118.178.0.0 netmask 255.255.0.0 gw 192.168.20.1
echo "Starting abc"
java -jar /home/pi/Downloads/abc.jar &
;;
stop)
echo "Stopping abc"
process='abc'
pid=$(ps x | grep $process | grep -v grep | awk '{print $1}')
kill $pid
;;
*)
echo "Usage: service daemon start|stop"
exit 1
;;
esac
exit 0
```
1.将shell脚本保存至/etc/init.d/ 目录下
/etc/init.d/MyShell start
/etc/init.d/MyShell stop
2.配置开机自动执行
添加: sudo update-rc.d 服务名 defaults
删除:sudo update-rc.d -f 服务名 remove
网友评论