Linux 在启动时运行

编程入门 行业动态 更新时间:2024-10-26 16:30:23
本文介绍了Linux 在启动时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在 raspberry pi 启动时启动一些进程.但由于某种原因,它没有按预期工作.这个想法是启动 Xvfb 和一些 jar 文件.

I'm trying to start some processes when my raspberry pi boots. But for some reason it doesn't work as expected. The idea is to start Xvfb and some jar file.

所以,我创建了一个脚本

So, I created a script

Xvfb :99 > /var/log/xvfb.log 2>&1 java -jar /home/pi/selenium-server/selenium-server-standalone-2.42.2.jar > /var/log/selenium.log 2>&1 echo "Servers started" >> /var/log/start_server.log date >> /var/log/start_server.log

然后用 cronjob 启动这个脚本:@reboot/var/bootscripts/start_servers

And then with a cronjob I start this script: @reboot /var/bootscripts/start_servers

但由于某种原因,jar 文件根本没有启动".是不是因为我将所有内容都发送到了日志文件中?

But for some reason, the jar file isn't 'started' at all. Is it because I sent everything to log files?

更新

好的,我找到了一些关于编写启动脚本的信息,所以我修改了我的脚本.

Okay, I found some information about writing a start script, so I modified my script.

#! /bin/sh # /etc/init.d/blah # # Run always > /var/log/xvfb.log # clear log date >> /var/log/test-server.log # write date to log > /var/log/xvfb.log # clear log date >> /var/log/xvfb.log # write date to log Xvfb :99 > /var/log/xvfb.log 2>&1 # write output to log > /var/log/selenium.log # clear log date >> /var/log/selenium.log # write date to log java -jar /home/pi/selenium-server/selenium-server-standalone-2.42.2.jar > /var/log/seleni$ echo "Servers started" >> /var/log/test-server.log # Carry out specific functions when asked to by the system # to do case "$1" in start) echo "Starting script blah " echo "Could do more here" ;; stop) echo "Stopping script blah" echo "Could do more here" ;; *) echo "Usage: /etc/init.d/blah {start|stop}" exit 1 ;; esac exit 0

它还没有完全完成(要执行#),但我首先想测试应该始终运行的命令.嗯,xvfb 启动(日志是完美的),但 java 服务器没有.没有创建 selenium.log 文件(所以它没有达到我想的那段代码).

It is not completly finished (# to do), but I first wanted to test the commands that should run always. Well, xvfb starts (log is perfect), but the java server doesn't. The selenium.log file isn't created (so it doesn't reach that piece of code I suppose).

如果我看到 test-server.log 我只看到日期,所以 echo 命令不起作用,或者更好地说:它没有到达命令.

If I see to test-server.log I only see the date, so the echo command doesn't work as well, or better said: it doesn't reach the command.

推荐答案

您很可能会遇到有关 cron 作业和 init 脚本的常见问题:环境变量未设置为您所期望的.

You have very likely run into a common problem with cron jobs and init scripts: the environment variables are not set to what you expect.

我建议明确设置变量.设置 PATH 和 HOME 值.如果 selenium 服务器需要 GUI,那么在您启动 Xvfb 之后,您需要设置 DISPLAY 和 XAUTHORITY.您可能还需要 USER.

I advise setting the variables explicitly. Set the PATH and HOME values. If selenium server needs a GUI then after you start Xvfb you need to set DISPLAY and perhaps XAUTHORITY. You might need USER as well.

对此的另一个评论:我不建议使用 cron 作业来执行此操作,尽管它会起作用.最好使用 SysV init 脚本、Upstart 作业或 systemd 单元执行此操作,具体取决于您的 Pi 正在运行的内容.

Another comment on that: I don't recommend doing this with a cron job, although it'll work. It would be better to do this with a SysV init script, or Upstart job or systemd unit, depending on what your Pi is running.

更多推荐

Linux 在启动时运行

本文发布于:2023-11-05 06:20:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560131.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:启动时   Linux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!