创建放置程序和配置文件的文件夹

1
2
3
4
mkdir /etc/config/abandon
cd /etc/config/abandon
# 上传相关文件到该目录
chmod +x abandon

创建服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cat << EOF > /etc/config/abandon/abandon.service
#!/bin/sh /etc/rc.common
# "new(er)" style init script
# Look at /lib/functions/service.sh on a running system for explanations of what other SERVICE_
# options you can use, and when you might want them.

START=80
SERVICE_DAEMONIZE=1

start() {
service_start /etc/config/abandon/abandon /etc/config/abandon/config.json
}

stop() {
kill -9 `ps | grep '/etc/config/abandon/abandon' | grep -v 'grep' | awk '{print $1}'`
}
EOF

注册服务并允许自启动

1
2
3
4
5
chmod +x /etc/config/abandon/abandon.service
ln -s /etc/config/abandon/abandon.service /etc/init.d/abandon
/etc/init.d/abandon enable
# 启动 /etc/init.d/abandon start
# 停止 /etc/init.d/abandon stop