首页 / UBUNTU / ubuntu自定义服务模板
ubuntu自定义服务模板
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ubuntu自定义服务模板,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1989字,纯文字阅读大概需要3分钟。
内容图文
![ubuntu自定义服务模板](/upload/InfoBanner/zyjiaocheng/1102/914930f9735847468c6613ec5584a17c.jpg)
根据他人代码修改:
1 #!/bin/sh 2### BEGIN INIT INFO 3 # Provides: <pragram name> 4 # Required-Start: $local_fs $network $named $time $syslog 5 # Required-Stop: $local_fs $network $named $time $syslog 6 # Default-Start: 2345 7 # Default-Stop: 016 8# Description: shrpx proxy 9### END INIT INFO 1011 PROG= #<pragram name> 12 PIDFILE= #<pid file full path> 13 LOGFILE= #<log file full path> 1415start() { 16if [ -f $PIDFILE ]; then17if ! pgrep $PROG; then18echo"Terminate abnormaly last time!"19rm -f $PIDFILE 20else21echo‘Service already running‘ >&222 return 123fi24fi2526if [ -n "$PIDFILE" ];then27 PIDFILE="&1"28fi2930echo‘Starting service...‘3132if $PROG >$LOGFILE; then33echo‘Service started‘34else35echo‘Start failed!‘ >&236fi37} 3839stop() { 40if [ ! -f "$PIDFILE" ]; then41echo‘Service not running‘ >&242 return 143fi44echo‘Stopping service…‘ >&145kill -KILL $(cat"$PIDFILE") 46rm -f "$PIDFILE"47echo‘Service stopped‘ >&148} 4950status(){ 51if [ -f "$PIDFILE" ];then52echo"$PROG is running"53else54echo"$PROG is stopped"55fi56} 5758uninstall() { 59echo"Are you really sure you want to uninstall this service?"60"That cannot be undone. [yes|No] "61 local SURE 62 read SURE 63if [ X"$SURE" = "Xyes" ]; then64 stop 65if [ -f $PIDFILE ]; then66rm -f "$PIDFILE"67fi68echo"Notice: log file is not be removed: ‘$LOGFILE‘" >&169 update-rc.d -f $PROG remove 70rm -fv "$0"71fi72} 7374case"$1"in75 start) 76 start 77 ;; 78 stop) 79 stop 80 ;; 81 uninstall) 82 uninstall 83 ;; 84 retart) 85 stop 86 start 87 ;; 88 status) 89 status 90 ;; 91 *) 92echo"Usage: $0 {start|stop|status|restart|uninstall}"93esac
使用方法:cp到/etc/init.d/下面,修改<>里面的内容,然后使用update-rc.d管理服务;
添加一个服务:sudo update-rc.d srv_name defaults
删除一个服务 :sudo
update-rc.d–f srv_name remove
default表示的是服务的运行优先级,默认是20,数字越小优先级越高。
以后就会开机自启动了,使用sudo service srv_name start|stop|status|restart|uninstall来做临时性的管理。
原文:http://www.cnblogs.com/livewithnorest/p/3533257.html
内容总结
以上是互联网集市为您收集整理的ubuntu自定义服务模板全部内容,希望文章能够帮你解决ubuntu自定义服务模板所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。