我有点菜鸟,我一直在关注这个教程在 ubuntu 20.04 上设置 rc.local,因为我想在启动时更改文件夹的所有权。
该脚本保存在 chownscript.sh 中,内容如下:
#!/bin/bash
chown -R 1001:1001 /opt/redis
exit 0
当我运行它时,sudo ./chownscript.sh
它运行良好。
我的 rc.local 文件是
#!/bin/sh -e
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Ensure that the script will "exit 0" on success or any other
# value on error.
#
# To enable or disable this script, just change the execution
# bits.
#
# By default, this script does nothing.
sh /opt/chownscript.sh
exit 0
我的 /etc/systemd/system/rc-local.service 文件是
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.targ[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
当我跑步时systemctl status rc-local.service
我得到
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)
Drop-In: /usr/lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (exited) since Wed 2023-03-29 19:55:53 UTC; 16min ago
Process: 651 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
CPU: 24ms
Mar 29 19:55:53 ubuntu-server-2 systemd[1]: Starting /etc/rc.local Compatibility...
Mar 29 19:55:53 ubuntu-server-2 sudo[653]: root : PWD=/ ; USER=root ; COMMAND=/usr/bin/chown -R 1001:1001 /opt/redis
Mar 29 19:55:53 ubuntu-server-2 sudo[653]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Mar 29 19:55:53 ubuntu-server-2 sudo[653]: pam_unix(sudo:session): session closed for user root
Mar 29 19:55:53 ubuntu-server-2 systemd[1]: Started /etc/rc.local Compatibility.
但是当我检查文件夹权限时,没有任何变化。有什么建议可以告诉我我做错了什么吗?