0

CentOS で pm2 を使用してサービスとして実行されるノード サーバー アプリケーションがあります。nodejs fsモジュールを含むすべての外部ドライブをリストする必要があります。root ユーザーがログインすると、完全に機能します。OS を再起動すると、pm2 はサーバーを再度実行しますが、ディレクトリを表示するためのアクセスはありません。

すべてのディレクトリを一覧表示するコードは次のとおりです。

const driveList = require('drivelist');
const fs = require('fs');
const path = require('path');
const emptyDir = require('empty-dir');

const config = require('../config.json');


exports.list_all_drives = function(req, res) {
    return driveList.list((err, drives) => {

        if(err) return res.status(500).send('there was an error');

        let isWin = /^win/.test(process.platform);

        let usbDrives = [];
        drives.map((drive) => {
            if(isWin){
                for(let index in drive.mountpoints){
                    usbDrives.push(drive.mountpoints[index].path);
                }
            }else{
                if(!drive.system){
                    for(let index in drive.mountpoints){
                        usbDrives.push(drive.mountpoints[index].path);
                    }
                }
            }
        });

        if(err) return res.status(500).send('there was an error');
        let records = [];
        usbDrives.forEach((name, i) => {
            let record = {};
            record.id = i;
            record.title = name;
            record.path = name;
            record.isDirectory = true;

            let skip = false;
            config.skipPath.forEach((val) => {
                if(record.path == val){
                    skip = true;
                }
            });

            if(!skip){
                records.push(record);
            }
        });
        res.status(200).send(records);
    });
};

ユーザーがログインすると、機能が動作し、すべての OS ディレクトリが一覧表示されますが、システムを再起動すると 500 エラーが返されます。

{"errno":-2,"code":"ENOENT","syscall":"open","path":"/run/user/0/drivelist-ecc75a4a9523.sh"}

4

0 に答える 0