Linux 设置开机自动启sh脚本

Linux 设置开机自动启sh脚本,第1张

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 要写绝对路径,不能写相对路径! 

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

原文地址: http://outofmemory.cn/zaji/5709306.html

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

发表评论

登录后才能评论

评论列表(0条)

保存