启动脚本未运行

启动脚本未运行

我正在使用 Ubuntu 20.04LTS,并尝试在启动时运行脚本。我在 /etc/init.d/ 中创建了它,赋予它 chmod 755 并运行 update-rc.d defaults 命令,但该程序在下次启动时不会执行。这是我的脚本

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

sudo /opt/lampp/lampp start
google-chrome
code

echo "Script run successfully"



exit 0

当我尝试直接运行脚本时

sudo service myscript.sh start

我收到此消息

● myscript.service
     Loaded: loaded (/etc/init.d/myscript.sh; generated)
     Active: failed (Result: exit-code) since Sat 2020-07-18 14:00:39 +06; 3min 31s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 12057 ExecStart=/etc/init.d/myscript.sh start (code=exited, status=1/FAILURE)
      Tasks: 39 (limit: 9344)
     Memory: 126.7M
     CGroup: /system.slice/myscript.service
             ├─12112 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
             ├─12117 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
             ├─12209 /bin/sh /opt/lampp/bin/mysqld_safe --datadir=/opt/lampp/var/mysql --pid-file=/opt/lampp/var/mysql/GraceHopper.pid
             ├─12226 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
             ├─12227 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
             ├─12228 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
             ├─12229 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
             ├─12230 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
             └─12358 /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --plugin-dir=/opt/lampp/lib/mysql/plugin/ --user=mysql --log-error=/opt/lampp/var/mysql/GraceHopper.err --pid-file=/opt/lampp/var/mysql/GraceHopper.pid --socket=/opt/lampp/var/mysql/mysql.sock --port=3306

Jul 18 14:00:39 GraceHopper myscript.sh[12113]: XAMP
Jul 18 14:00:39 GraceHopper myscript.sh[12080]: XAMP
Jul 18 14:00:39 GraceHopper myscript.sh[12080]: AMPP: Starting MySQ
Jul 18 14:00:39 GraceHopper sudo[12058]: pam_unix(sudo:session): session closed for user root
Jul 18 14:00:39 GraceHopper myscript.sh[12124]: AMPP
Jul 18 14:00:39 GraceHopper myscript.sh[12131]: AMPP
Jul 18 14:00:39 GraceHopper systemd[1]: myscript.service: Control process exited, code=exited, status=1/FAILURE
Jul 18 14:00:39 GraceHopper systemd[1]: myscript.service: Failed with result 'exit-code'.
Jul 18 14:00:39 GraceHopper systemd[1]: Failed to start myscript.service.
Jul 18 14:00:41 GraceHopper myscript.sh[12131]: 12125:12125:0718/140039.216854:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/6381

答案1

/etc/rc.local在系统启动时运行root(所以你的sudo没用)。

这是在您登录之前,并且在 X 服务器启动之前,因此chrome没有可显示的显示。

这属于$HOME/.config/autostart

相关内容