systemd管理服务

[root@zbs-staging-api system]# cat /lib/systemd/system/ncmulti@.service 
[Unit]
Description=many on %i
After=network.target

[Service]
PIDFile=/var/run/nc.%i.pid
#Type=forking
ExecStart=/usr/bin/nc -l %i # 命令行执行时在@后传递变量

[Install]
WantedBy=multi-user.target


#一条命令启动一个进程

[root@zbs-staging-api system]# systemctl start ncmulti@5733
[root@zbs-staging-api system]# systemctl start ncmulti@5734
[root@zbs-staging-api system]# systemctl start ncmulti@5732

[root@zbs-staging-api system]# ps aux | grep nc
root 19599 0.0 0.0 45676 2080 ? Ss 20:24 0:00 /usr/bin/nc -l 5735
root 19616 0.0 0.0 45676 2080 ? Ss 20:24 0:00 /usr/bin/nc -l 5733
root 19622 0.0 0.0 45676 2076 ? Ss 20:24 0:00 /usr/bin/nc -l 5734
root 19628 0.0 0.0 45676 2080 ? Ss 20:24 0:00 /usr/bin/nc -l 5732

#一条命令启动多个进程

[root@zbs-staging-api system]# systemctl start ncmulti@{9283,9282,9284} 或者 systemctl start ncmulti@{9282..9284}

[root@zbs-staging-api system]# ps aux | grep nc
root 19948 0.0 0.0 45676 2076 ? Ss 20:26 0:00 /usr/bin/nc -l 9283
root 19949 0.0 0.0 45676 2076 ? Ss 20:26 0:00 /usr/bin/nc -l 9282
root 19950 0.0 0.0 45676 2076 ? Ss 20:26 0:00 /usr/bin/nc -l 9284

[root@zbs-staging-api system]# systemctl restart ncmulti@{9283,9282,9284} #批量重启
[root@zbs-staging-api system]# ps aux | grep nc
root 19959 0.0 0.0 45676 2080 ? Ss 20:27 0:00 /usr/bin/nc -l 9283
root 19962 0.0 0.0 45676 2076 ? Ss 20:27 0:00 /usr/bin/nc -l 9282
root 19963 0.0 0.0 45676 2076 ? Ss 20:27 0:00 /usr/bin/nc -l 9284

 

# 启动多进程传递有序参数

systemctl start storage@sd{b..m}

 

转载于:https://www.cnblogs.com/yooma/p/8244776.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值