linux centos 开机自启动 tomcat (解决 env: /etc/init.d/tomcat: No such file or directory)
2017-03-08 00:00
811 查看
先来个简单无脑的教程,使用shell脚本来启动
1.先进入该目录
2.在此目录下创建tomcat文件,service tomcat start|stop 就是使用的该文件,文件内容如下,里面的jdk和tomcat的路径请根据自己实际情况修改
3.给予该文件权限
4.把该文件挂载到rc上,启动rc*.d中*多少代表优先级0最优先,为了顺利自启动可适当将优先级降低
5.将脚本设置自动启动
至此基本完成了,可以reboot试试了
下面是填坑了,一些复制我脚本的童鞋发现重启没效果或者在使用 service tomcat start 可能会遇到该错误
"env: /etc/init.d/tomcat: No such file or directory)"
这是为甚呢,因为你在windows下保存了该脚本文件,其中的换行符被改变了,windows中换行符为/r/n
而linux中是/n 所以这边需要把脚本做个转换,我们使用dos2unix,一般大家可能都没装该工具,好人做到底,送福送到西 安装其实很简单
安装完成后直接执行既可
再使用service tomcat start 就没问题啦
顺便再提一句 /etc/init.d/tomcat 和 /etc/rc.d/init.d/tomcat 是同一个东西!
1.先进入该目录
cd /etc/init.d/
2.在此目录下创建tomcat文件,service tomcat start|stop 就是使用的该文件,文件内容如下,里面的jdk和tomcat的路径请根据自己实际情况修改
#!/bin/sh # chkconfig: 345 99 10 # description: Auto-starts tomcat # Auther: Lex Mc # /etc/init.d/tomcatd # Tomcat auto-start # Source function library. #. /etc/init.d/functions # source networking configuration. #. /etc/sysconfig/network RETVAL=0 export JAVA_HOME=/usr/local/jdk export JRE_HOME=/usr/local/jdk/jre export CATALINA_HOME=/usr/local/tomcat export CATALINA_BASE=/usr/local/tomcat start() { if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" $CATALINA_HOME/bin/startup.sh RETVAL=$? echo " OK" return $RETVAL fi } stop() { if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" $CATALINA_HOME/bin/shutdown.sh RETVAL=$? sleep 1 ps -fwwu root | grep tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9 echo " OK" # [ $RETVAL -eq 0 ] && rm -f /var/lock/... return $RETVAL fi } case "$1" in start) start ;; stop) stop ;; restart) echo $"Restaring Tomcat" $0 stop sleep 1 $0 start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 ;; esac exit $RETVAL
3.给予该文件权限
chmod u+x /etc/init.d/tomcat
4.把该文件挂载到rc上,启动rc*.d中*多少代表优先级0最优先,为了顺利自启动可适当将优先级降低
ln -s /etc/init.d/tomcat /etc/rc3.d/S16Tomcat
5.将脚本设置自动启动
chkconfig --add tomcat
chkconfig tomcat on
至此基本完成了,可以reboot试试了
下面是填坑了,一些复制我脚本的童鞋发现重启没效果或者在使用 service tomcat start 可能会遇到该错误
"env: /etc/init.d/tomcat: No such file or directory)"
这是为甚呢,因为你在windows下保存了该脚本文件,其中的换行符被改变了,windows中换行符为/r/n
而linux中是/n 所以这边需要把脚本做个转换,我们使用dos2unix,一般大家可能都没装该工具,好人做到底,送福送到西 安装其实很简单
yum install dos2unix
安装完成后直接执行既可
dos2unix /etc/init.d/tomcat
再使用service tomcat start 就没问题啦
顺便再提一句 /etc/init.d/tomcat 和 /etc/rc.d/init.d/tomcat 是同一个东西!
相关文章推荐
- can't run '/etc/init.d/rcS': No such file or directory 最终解决方法
- 解决:cant't run '/etc/init.d/rcS':No such file or directory
- nginx运行文件出错env: /etc/init.d/nginx: No such file or directory
- nginx运行文件出错env: /etc/init.d/nginx: No such file or directory
- 解决/etc/init.d/ceph: line 15: /lib/lsb/init-functions: No such file or directory
- 解决:cant't run '/etc/init.d/rcS':No such file or directory
- /etc/init.d/mysql: No such file or directory 和 ERROR 2002 (HY000): Can't connect to local MySQL server through socket 解决办法
- can't run '/etc/init.d/rcS': No such file or directory解决方法
- /usr/bin/env: php: No such file or directory 【xunsearch demo项目体验】【已解决】
- cocoapods安装出现env: ruby_executable_hooks: No such file or directory(已解决)
- 嵌入式开发板上自启动qt程序调用ts_calibrate 发生ts_open : No such file or directory 解决办法
- Ceph部署时提示:/etc/init.d/ceph: line 15: /lib/lsb/init-functions: No such file or directory
- env: ruby_executable_hooks: No such file or directory解决方法
- 解决 /etc/postfix/main.cf: No such file or directory
- env: ruby_executable_hooks: No such file or directory的解决办法
- 解决mac os下mcss命令报错:env: node\r: No such file or directory
- 解决cocoaPods插件报错:env: ruby_executable_hooks: No such file or directory
- 运行docker容器时报standard_init_linux.go:195: exec user process caused "no such file or directory" 的解决方法
- /etc/rc.d/init.d/iptables: No such file or directory 错误原因
- hadoop2.5.2中执行 $ bin/hdfs dfs -put etc/hadoop input遇到put: `input': No such file or directory的解决办法