【问题标题】:I get "(Read-only file system)" when try to write a file on HD尝试在 HD 上写入文件时出现“(只读文件系统)”
【发布时间】:2019-11-14 07:59:56
【问题描述】:

我想使用运行在Tomcat9上的springboot servlet在这个路径下写一个文件

/mnt/data-new/data/USERPROFILE/607/file.txt 

当我尝试写入该文件时,我收到此错误:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Jul 03 14:11:39 UTC 2019
There was an unexpected error (type=Internal Server Error, status=500).
/mnt/data-new/data/USERPROFILE/607/file.txt (Read-only file system)

我已经使用 777 在该路径上设置了权限,但没有任何改变。

Servlet 代码非常简单:

@GetMapping("/")
public String index() throws IOException {
     FileWriter fw = new FileWriter("/mnt/data-new/data/USERPROFILE/607/file.txt");
     fw.write("File wrote");
     fw.close();
     return "OK";
}

我创建了一个名为“file2.txt”的文件,我可以使用此示例代码读取该文件:

@ResponseBody
@GetMapping("/read")
public String read() throws IOException {
    BufferedReader br = new BufferedReader(new FileReader("/mnt/data-new/data/USERPROFILE/607/file2.txt"));

    String st;
    while ((st = br.readLine()) != null) return st;
    return null;
}

我以为这是 catalina 政策,但似乎已禁用:

root@devel-spring:/etc/tomcat9# echo $CATALINA_OPTS
-Djava.security.debug=all

而且,即使使用此选项,我在“/var/log/syslog”中也没有安全管理器日志

我应该怎么做才能在那个绝对路径中写入文件?

编辑: 文件系统是 RW 挂载的,我可以使用 bash 创建该文件。

【问题讨论】:

    标签: file spring-boot ubuntu io tomcat9


    【解决方案1】:

    感谢 debian bugs.debian.org 中的 Emmanuel Bourg link 我发现了 Tomcat9

    “被沙盒化,只能写入它自己的目录。你必须 调整 systemd 配置以允许 Tomcat 写入..." [那个]“...目录”。

    所以我添加了 /etc/systemd/system/multi-user.target.wants/tomcat9.service

    ReadWritePaths=/mnt/data-new/data/
    

    然后

    systemctl daemon-reload
    service tomcat9 restart
    

    现在,

    使用上面的代码,我成功地编写了我的测试文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-12
      • 2017-10-18
      相关资源
      最近更新 更多