Systemd服务管理
1.查看服务启动级别WantedBy=multi-user.target
2.查看状态
systemctl status sshd.service
3.启动服务
systemctl start sshd.service
4.重启服务
systemctl restart sshd.service
5.关闭服务
systemctl stop sshd.service
6.重载服务
systemctl reload sshd.service
7.开机启动
systemctl enable sshd.service
8.开机关闭
systemctl disable sshd.serivce
9.是否开机启动
systemctl is-enabled sshd.service
10.是否启动
systemctl is-active sshd.serivce
自定义startMyApp.sh脚本程序:
vi /mnt/startMyApp.sh
#!/bin/sh
i=0
while true
do
echo $i>>/mnt/MyApp.txt
((i++))
sleep 1
done
给脚本设置执行权限:
chmod a+x startMyApp.sh
自定义myapp服务脚本:
vi /etc/systemd/system/myapp.service
Description=myapp service
Type=simple
WorkingDirectory=/mnt
ExecStart=/mnt/startMyApp.sh
ExecStop=/bin/kill -s TERM $MAINPID
WantedBy=multi-user.target
把myapp服务加入开机启动:
systemctl enable myapp.service
启动myapp服务:
systemctl start myapp.service
关闭myapp服务:
systemctl stop myapp.service
查看myapp服务状态:
systemctl status myapp.service
页:
[1]