Linux 设置开机自动启sh脚本

设置流程

vim /usr/lib/systemd/system/maomao.service

[Unit]
Description=The java application maomao for LMEnglish serve
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
PIDFile=/server/maomao/maomao.pid
ExecStart=/server/maomao/run.sh start

[Install]
WantedBy=multi-user.target
~                                         

相关命令:

systemctl enable maomao.service

systemctl start maomao.service

systemctl status maomao.service

有报错:

[root@iZbp18qk0bio1jludfhze4Z system]# systemctl status maomao.service
● maomao.service - The java application maomao for LMEnglish serve
   Loaded: loaded (/usr/lib/systemd/system/maomao.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2022-01-17 23:08:08 CST; 5s ago
  Process: 1602 ExecStart=/server/maomao/run.sh start (code=exited, status=203/EXEC)
 Main PID: 1602 (code=exited, status=203/EXEC)

Jan 17 23:08:08 iZbp18qk0bio1jludfhze4Z systemd[1]: Started The java application maomao for LMEnglish serve.
Jan 17 23:08:08 iZbp18qk0bio1jludfhze4Z systemd[1]: maomao.service: Main process exited, code=exited, status=203/EXEC
Jan 17 23:08:08 iZbp18qk0bio1jludfhze4Z systemd[1]: maomao.service: Failed with result 'exit-code'.
[root@iZbp18qk0bio1jludfhze4Z system]# systemctl status maomao.service
● maomao.service - The java application maomao for LMEnglish serve
   Loaded: loaded (/usr/lib/systemd/system/maomao.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2022-01-17 23:08:08 CST; 5min ago
  Process: 1602 ExecStart=/server/maomao/run.sh start (code=exited, status=203/EXEC)
 Main PID: 1602 (code=exited, status=203/EXEC)

Jan 17 23:08:08 iZbp18qk0bio1jludfhze4Z systemd[1]: Started The java application maomao for LMEnglish serve.
Jan 17 23:08:08 iZbp18qk0bio1jludfhze4Z systemd[1]: maomao.service: Main process exited, code=exited, status=203/EXEC
Jan 17 23:08:08 iZbp18qk0bio1jludfhze4Z systemd[1]: maomao.service: Failed with result 'exit-code'.

看一下脚本:

不太对,默认没有设置脚本的执行权限,

加上权限:

[root@iZbp4Z maomao]# chmod a+x run.sh 

再看

正常了!

再执行:

systemctl start maomao.service

看着稳了:

再看看应用怎么样,发现屁都没有!

真是头疼,再看看!

看一下应用日志提示:

systemctl Error: Unable to access jarfile 

原来是没有权限执行jar 包!

又赶紧改一下权限:

chmod a+x maomao.jar

还是不行。

终于开窍了!

原来run.sh 中的jar 要写绝对路径,不能写相对路径! 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值