Fedora如何实现自动运行

本文介绍如何在Linux环境下创建服务启动脚本,并通过chkconfig工具实现服务的自动启动。主要内容包括:创建符合规范的init脚本、使用chkconfig进行服务管理及验证服务是否正确配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.在/etc/init.d/中创建脚本,运用如下的格式

#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
    # code to start app comes here 
    # example: daemon program_name &
}

stop() {
    # code to stop app comes here 
    # example: killproc program_name
}

case "$1" in 
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here 
       # example: status program_name
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac

exit 0 
可以参考/etc/init.d/中其他的脚本实现如上格式的脚本,创建完之后可以运行script,/etc/init.d/myscript start 或者chkconfig myscript start.

2、使能脚本实现脚本自动运行

$ chkconfig --add myscript 
$ chkconfig --level 2345 myscript on
3、检查脚本是否配置成功

$ chkconfig --list | grep myscript

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值