将脚本制作成linux服务

将脚本制作成linux服务,第1张

概述– 编辑,还有一些问题 – 好我的脚本使用循环来等待网络连接.因此,当我运行它时,即使使用守护进程,它也只是坐在那里而不是让我回到shell.我试过su -c“/ home / webreports / report-list&” USER但它试图以用户身份运行&即使我有引号,我甚至尝试过单引号. – 原版的 – 我已经制作了一个脚本(尚未测试),用于将bash脚本作为服务运行.我有两个问题. 1 – 编辑,还有一些问题 –

好我的脚本使用循环来等待网络连接.因此,当我运行它时,即使使用守护进程,它也只是坐在那里而不是让我回到shell.我试过su -c“/ home / webreports / report-List&” USER但它试图以用户身份运行&即使我有引号,我甚至尝试过单引号.

– 原版的 –
我已经制作了一个脚本(尚未测试),用于将bash脚本作为服务运行.我有两个问题.

1)如何让它作为特定用户运行?我们使用的软件不能以root身份运行,并且如果它确实会崩溃(可怕的软件我们很遗憾).那么如何让用户“JOEBOB”让它运行服务呢.

2)我是否只将脚本文件放入“/etc/rc5.d”以便能够使用“service report-Listen start”?

—脚本 –

#!/bin/sh## myservice     This shell script takes care of starting and stopPing#               the /home/webreports/report-Listen## Source function library. /etc/rc.d/init.d/functions# Do preliminary checks here,if any#### START of preliminary checks ############## END of preliminary checks ######## Handle manual control parameters like start,stop,status,restart,etc.case "" in  start)    # Start daemons.    echo -n $"Starting report-Listen daemon: "    echo    daemon /home/webreports/report-Listen    echo    ;;  stop)    # Stop daemons.    echo -n $"Shutting down report-Listen: "    killproc /home/webreports/report-Listen    echo    # Do clean-up works here like removing pID files from /var/run,etc.    ;;  status)    status /home/webreports/report-Listen    ;;  restart)    
daemon su -c /home/webreports/report-Listen johndoe
stop start ;; *) echo $"Usage: {start|stop|status|restart}" exit 1esacexit 0
解决方法 使用su以不同的用户身份运行脚本:

其中johndoe是您希望它运行的用户.

将脚本放在/etc/init.d/myservice中,然后将其符号链接到/etc/rc.d/S99myservice.

总结

以上是内存溢出为你收集整理的将脚本制作成linux服务全部内容,希望文章能够帮你解决将脚本制作成linux服务所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/1040679.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存