将脚本制作成linux服务
发布时间:2020-12-13 17:11:50 所属栏目:Linux 来源:网络整理
导读:– 编辑,还有一些问题 – 好我的脚本使用循环来等待网络连接.因此,当我运行它时,即使使用守护进程,它也只是坐在那里而不是让我回到shell.我试过su -c“/ home / webreports / report-list” USER但它试图以用户身份运行即使我有引号,我甚至尝试过单引号. –
– 编辑,还有一些问题 –
好我的脚本使用循环来等待网络连接.因此,当我运行它时,即使使用守护进程,它也只是坐在那里而不是让我回到shell.我试过su -c“/ home / webreports / report-list&” USER但它试图以用户身份运行&即使我有引号,我甚至尝试过单引号. – 原版的 – 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 "$1" 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) $0 stop $0 start ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 1 esac exit 0 解决方法
使用su以不同的用户身份运行脚本:
daemon su -c /home/webreports/report-listen johndoe 其中johndoe是您希望它运行的用户. 将脚本放在/etc/init.d/myservice中,然后将其符号链接到/etc/rc.d/S99myservice. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |