Connect mongod exiting with code 1, can not see specific any error in log file

Very sorry for my short question but I don’t know how to describe my problem. Here is info when I try to run mongo shell:

    MongoDB shell version v5.0.3
    connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
    Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
    connect@src/mongo/shell/mongo.js:372:17
    @(connect):2:6
    exception: connect failed
    exiting with code 1

And here are some logs:

    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"NETWORK",  "id":23017,   "ctx":"listener","msg":"removing socket file","attr":{"path":"/tmp/mongodb-27017.sock"}}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"NETWORK",  "id":4784905, "ctx":"SignalHandler","msg":"Shutting down the global connection pool"}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"CONTROL",  "id":4784906, "ctx":"SignalHandler","msg":"Shutting down the FlowControlTicketholder"}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"-",        "id":20520,   "ctx":"SignalHandler","msg":"Stopping further Flow Control ticket acquisitions."}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"CONTROL",  "id":4784908, "ctx":"SignalHandler","msg":"Shutting down the PeriodicThreadToAbortExpiredTransactions"}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"REPL",     "id":4784909, "ctx":"SignalHandler","msg":"Shutting down the ReplicationCoordinator"}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"SHARDING", "id":4784910, "ctx":"SignalHandler","msg":"Shutting down the ShardingInitializationMongoD"}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"REPL",     "id":4784911, "ctx":"SignalHandler","msg":"Enqueuing the ReplicationStateTransitionLock for shutdown"}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"-",        "id":4784912, "ctx":"SignalHandler","msg":"Killing all operations for shutdown"}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"-",        "id":4695300, "ctx":"SignalHandler","msg":"Interrupted all currently running operations","attr":{"opsKilled":3}}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"TENANT_M", "id":5093807, "ctx":"SignalHandler","msg":"Shutting down all TenantMigrationAccessBlockers on global shutdown"}
    {"t":{"$date":"2021-10-20T16:32:14.249+07:00"},"s":"I",  "c":"COMMAND",  "id":4784913, "ctx":"SignalHandler","msg":"Shutting down all open transactions"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"REPL",     "id":4784914, "ctx":"SignalHandler","msg":"Acquiring the ReplicationStateTransitionLock for shutdown"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"INDEX",    "id":4784915, "ctx":"SignalHandler","msg":"Shutting down the IndexBuildsCoordinator"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"REPL",     "id":4784916, "ctx":"SignalHandler","msg":"Reacquiring the ReplicationStateTransitionLock for shutdown"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"REPL",     "id":4784917, "ctx":"SignalHandler","msg":"Attempting to mark clean shutdown"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"NETWORK",  "id":4784918, "ctx":"SignalHandler","msg":"Shutting down the ReplicaSetMonitor"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"SHARDING", "id":4784921, "ctx":"SignalHandler","msg":"Shutting down the MigrationUtilExecutor"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"ASIO",     "id":22582,   "ctx":"MigrationUtil-TaskExecutor","msg":"Killing all outstanding egress activity."}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"COMMAND",  "id":4784923, "ctx":"SignalHandler","msg":"Shutting down the ServiceEntryPoint"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"CONTROL",  "id":4784925, "ctx":"SignalHandler","msg":"Shutting down free monitoring"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"CONTROL",  "id":20609,   "ctx":"SignalHandler","msg":"Shutting down free monitoring"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"CONTROL",  "id":4784927, "ctx":"SignalHandler","msg":"Shutting down the HealthLog"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"CONTROL",  "id":4784928, "ctx":"SignalHandler","msg":"Shutting down the TTL monitor"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"INDEX",    "id":3684100, "ctx":"SignalHandler","msg":"Shutting down TTL collection monitor thread"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"INDEX",    "id":3684101, "ctx":"SignalHandler","msg":"Finished shutting down TTL collection monitor thread"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"CONTROL",  "id":4784929, "ctx":"SignalHandler","msg":"Acquiring the global lock for shutdown"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"CONTROL",  "id":4784930, "ctx":"SignalHandler","msg":"Shutting down the storage engine"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"STORAGE",  "id":22320,   "ctx":"SignalHandler","msg":"Shutting down journal flusher thread"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"STORAGE",  "id":22321,   "ctx":"SignalHandler","msg":"Finished shutting down journal flusher thread"}
    {"t":{"$date":"2021-10-20T16:32:14.250+07:00"},"s":"I",  "c":"STORAGE",  "id":22322,   "ctx":"SignalHandler","msg":"Shutting down checkpoint thread"}
    {"t":{"$date":"2021-10-20T16:32:14.251+07:00"},"s":"I",  "c":"STORAGE",  "id":22323,   "ctx":"SignalHandler","msg":"Finished shutting down checkpoint thread"}
    {"t":{"$date":"2021-10-20T16:32:14.251+07:00"},"s":"I",  "c":"STORAGE",  "id":20282,   "ctx":"SignalHandler","msg":"Deregistering all the collections"}
    {"t":{"$date":"2021-10-20T16:32:14.251+07:00"},"s":"I",  "c":"STORAGE",  "id":22261,   "ctx":"SignalHandler","msg":"Timestamp monitor shutting down"}
    {"t":{"$date":"2021-10-20T16:32:14.251+07:00"},"s":"I",  "c":"STORAGE",  "id":22317,   "ctx":"SignalHandler","msg":"WiredTigerKVEngine shutting down"}
    {"t":{"$date":"2021-10-20T16:32:14.251+07:00"},"s":"I",  "c":"STORAGE",  "id":22318,   "ctx":"SignalHandler","msg":"Shutting down session sweeper thread"}
    {"t":{"$date":"2021-10-20T16:32:14.251+07:00"},"s":"I",  "c":"STORAGE",  "id":22319,   "ctx":"SignalHandler","msg":"Finished shutting down session sweeper thread"}
    {"t":{"$date":"2021-10-20T16:32:14.251+07:00"},"s":"I",  "c":"STORAGE",  "id":4795902, "ctx":"SignalHandler","msg":"Closing WiredTiger","attr":{"closeConfig":"leak_memory=true,"}}
    {"t":{"$date":"2021-10-20T16:32:14.252+07:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"SignalHandler","msg":"WiredTiger message","attr":{"message":"[1634722334:252129][142289:0x7f6df9745700], close_ckpt: [WT_VERB_CHECKPOINT_PROGRESS] saving checkpoint snapshot min: 18, snapshot max: 18 snapshot count: 0, oldest timestamp: (0, 0) , meta checkpoint timestamp: (0, 0) base write gen: 7"}}
    {"t":{"$date":"2021-10-20T16:32:14.274+07:00"},"s":"I",  "c":"STORAGE",  "id":4795901, "ctx":"SignalHandler","msg":"WiredTiger closed","attr":{"durationMillis":23}}
    {"t":{"$date":"2021-10-20T16:32:14.274+07:00"},"s":"I",  "c":"STORAGE",  "id":22279,   "ctx":"SignalHandler","msg":"shutdown: removing fs lock..."}
    {"t":{"$date":"2021-10-20T16:32:14.274+07:00"},"s":"I",  "c":"-",        "id":4784931, "ctx":"SignalHandler","msg":"Dropping the scope cache for shutdown"}
    {"t":{"$date":"2021-10-20T16:32:14.274+07:00"},"s":"I",  "c":"FTDC",     "id":4784926, "ctx":"SignalHandler","msg":"Shutting down full-time data capture"}
    {"t":{"$date":"2021-10-20T16:32:14.274+07:00"},"s":"I",  "c":"FTDC",     "id":20626,   "ctx":"SignalHandler","msg":"Shutting down full-time diagnostic data capture"}
    {"t":{"$date":"2021-10-20T16:32:14.279+07:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"SignalHandler","msg":"Now exiting"}
    {"t":{"$date":"2021-10-20T16:32:14.279+07:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"SignalHandler","msg":"Shutting down","attr":{"exitCode":0}}

but when I run sudo mongod -f /etc/mongod.conf, I can connect to mongo shell

Hi @MAY_CHEAPER,

Were you able to find a solution to your issue? Your log snippet starts after shutdown has initiated, so I think the most interesting log lines are missing.

If sudo mongod works fine, my first guess would be that there are problems with file & directory permissions that are ignored when you use sudo to start the mongod process as the root user.

If so, I recommend fixing file & directory permissions so your mongod process can run as an unprivileged user.

Regards,
Stennie