linux service

1.按一定的规则编写服务脚本,比如:myserviced


#!/bin/sh  
#chkconfig: 2345 80 05   
#description: myservice   
  
case $1 in  
start)  
    echo "myservice startup" #将该行替换成你自己的服务启动命令  
    ;;  
stop)  
    echo "myservice stop" #将该行替换成你自己服务的启动命令  
    ;;  
restart)  
    echo "myservice stop" #...  
    echo "myservice startup" #...  
    ;;  
*)  
    ;;  
esac  




命令解析:
# chkconfig: 2345 80 5
2345表示服务的运行级别,80代表Start的顺序,05代表Kill(Stop)的顺序;
# description: service_description
该服务的描述


2.将编写的脚本放到/etc/init.d/,将myserviced的访问权限加上“可执行”
[plain] view plain copy print?
chmod +x myserviced  


3.增加服务
[plain] view plain copy print?
chkconfig --add myserviced  


4.启停服务
[plain] view plain copy print?
service myserviced start  
service myserviced stop  


服务添加完成
可以用:chkconfig --list查看当前系统的服务
可以用:chkconfig --del myserviced删除服务


5.添加开机自启动
chkconfig --level 2345 myservice off


systemctl is-enabled test.service #查询服务是否开机启动




#systemd查看开机自启动的程序
ls /etc/systemd/system/multi-user.target.wants/




#将进程服务在后台运行
nohup shell命令 &


0、1和2分别表示标准输入、标准输出和标准错误信息输出,可以用来指定需要重定向的标准输入或输出。
由于使用nohup时,会自动将输出写入nohup.out文件中,如果文件很大的话,nohup.out就会不停的增大,这是我们不希望看到的,因此,可以利用/dev/null来解决这个问题。


nohup shell命令 >/dev/null 2>log &
如果错误信息也不想要的话:
nohup shell命令 >/dev/null 2>&1 &
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值