自定义一个函数供后续方便使用

在bash配置文件(通常是.bashrc.bash_profile等)中定义一个名为reloadctl的函数:

最终实际执行的是(全局生效):

vi /etc/profile

 

 1 reloadctl() {
 2     if [ "$#" -ne 2 ]; then
 3         echo "Usage: hehe -n <service_name>"
 4         return 1
 5     fi
 6 
 7     if [ "$1" != "-n" ]; then
 8         echo "Usage: hehe -n <service_name>"
 9         return 1
10     fi
11 
12     service_name="$2"
13 
14     systemctl daemon-reload
15     systemctl start "$service_name.service"
16     systemctl enable "$service_name.service"
17     systemctl status "$service_name.service"
18 }

然后source 一下生效;

接下来就可以调用:

reloadctl -n digg.api

实际执行的就是:

systemctl daemon-reload
systemctl start digg.api.service
systemctl enable digg.api.service
systemctl status digg.api.service

 

posted @ 2023-12-11 17:27  oct  阅读(7)  评论(0)    收藏  举报