1.自定义startMyApp.sh脚本程序:
vi /mnt/startMyApp.sh
#!/bin/sh
i=0
while true
do
echo $i>>/mnt/MyApp.txt
((i++))
sleep 1
done
2.给脚本设置执行权限:
chmod a+x startMyApp.sh
3.自定义myapp服务脚本:
vi /etc/systemd/system/myapp.service
[Unit]
Description=myapp service#描述
[Service]
Type=simple
WorkingDirectory=/脚本地址
ExecStart=/脚本地址/需要执行的脚本
ExecStop=/bin/kill -s TERM $MAINPID #关闭
[Install]
WantedBy=multi-user.target
4.重载
systemctl daemon-reload
4.把myapp服务加入开机启动:
systemctl enable myapp.service
5.启动myapp服务:
systemctl start myapp.service
6.关闭myapp服务:
systemctl stop myapp.service
7.查看myapp服务状态:
systemctl status myapp.service