node systemctl for discord.js bot error EACCES - node.js

I want to start my discord.js bot with a systemctl.
When I enter
[Unit]
Description=Bots by Tjum28
After=network-online.target
[Service]
User=pi
Type=simple
ExecStart=/usr/bin/node /home/pi/Bots/bot.js
[Install]
WantedBy=multi-user.target
this in my .service file the bot starts but when I send a message I get this error:
Before I send a message:
● bot.service - Bots by Tjum28
Loaded: loaded (/lib/systemd/system/bot.service; disabled; vendor preset: enabled)
Active: active (running) since Thu 2021-03-25 19:01:05 CET; 13s ago
Main PID: 9627 (node)
Tasks: 11 (limit: 2062)
CGroup: /system.slice/bot.service
└─9627 /usr/bin/node /home/pi/Bots/bot.js
Mar 25 19:01:05 Server systemd[1]: Started Bots by Tjum28.
Mar 25 19:01:10 Server node[9627]: Bot ist gestartet und einsatzbereit als T&M Transporte
After I send a message:
● bot.service - Bots by Tjum28
Loaded: loaded (/lib/systemd/system/bot.service; disabled; vendor preset: enabled)
Active: active (running) since Thu 2021-03-25 19:01:05 CET; 13s ago
Main PID: 9627 (node)
Tasks: 11 (limit: 2062)
CGroup: /system.slice/bot.service
└─9627 /usr/bin/node /home/pi/Bots/bot.js
Mar 25 19:01:05 Server systemd[1]: Started Bots by Tjum28.
Mar 25 19:01:10 Server node[9627]: Bot ist gestartet und einsatzbereit als T&M Transporte
Mar 25 19:01:18 Server node[9627]: [Error: EACCES: permission denied, open './xpfile.json'] {
Mar 25 19:01:18 Server node[9627]: errno: -13,
Mar 25 19:01:18 Server node[9627]: code: 'EACCES',
Mar 25 19:01:18 Server node[9627]: syscall: 'open',
Mar 25 19:01:18 Server node[9627]: path: './xpfile.json'
Mar 25 19:01:18 Server node[9627]: }
I use a rank system with a .json file.
I know that there is a problem with the .json file (xpfile.json) but I don't know how to fix it.
Here is the import in my bot.js file
let xpfile = JSON.parse(fs.readFileSync("/home/pi/Bots/xpfile.json", "utf8"));
The result from ls -l /home/pi/Bots/xpfile.json:
-rwxr-xr-x 1 pi pi 7416 [...] /home/pi/Bots/xpfile.json
When I start the bot with screen all is fine.

Related

what happen in rocketchat service

when I run the command
sudo systemctl enable --now rocketchat
sudo systemctl status --now rocketchat
● rocketchat.service - The Rocket.Chat server
Loaded: loaded (/lib/systemd/system/rocketchat.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2022-12-18 16:48:30 CST; 9s ago
Process: 30676 ExecStart=/root/.nvm/versions/node/v19.3.0/bin/node /opt/Rocket.Chat/main.js (code=exited, status=203/EXEC)
Main PID: 30676 (code=exited, status=203/EXEC)
Dec 18 16:48:30 iZbp10iedgidvzsp3ltox5Z systemd[1]: Started The Rocket.Chat server.
Dec 18 16:48:30 iZbp10iedgidvzsp3ltox5Z systemd[30676]: rocketchat.service: Failed to execute command: Permission denied
Dec 18 16:48:30 iZbp10iedgidvzsp3ltox5Z systemd[30676]: rocketchat.service: Failed at step EXEC spawning /root/.nvm/versions/node/v19.3.0/bin/node: Permission denied
Dec 18 16:48:30 iZbp10iedgidvzsp3ltox5Z systemd[1]: rocketchat.service: Main process exited, code=exited, status=203/EXEC
Dec 18 16:48:30 iZbp10iedgidvzsp3ltox5Z systemd[1]: rocketchat.service: Failed with result 'exit-code'.
I don't kown which command is denieded
-rwxrwxrwx 1 admin admin 92571400 Dec 14 19:22 /root/.nvm/versions/node/v19.3.0/bin/node*
Can you tell me how to solve this problem?

RabbitMQ server won't start anymore after assigning username/password

I installed a rabbitmq server and it was active and running fine until I entered:
echo "[{loopback_users, []}]}]." > /etc/rabbitmq/rabbitmq.config
I also assigned a username and password and also assigned the user as administrator. I tried to restart the server after that and it wouldn't restart. Checked the status and it was no longer running. Any idea what I did wrong? Still a rookie, any tips would be great.
[root#rmq01 ~]# systemctl status rabbitmq-server.service -l
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Fri 2022-08-12 05:47:22 UTC; 1s ago
Process: 1807 ExecStop=/usr/sbin/rabbitmqctl shutdown (code=exited, status=0/SUCCESS)
Process: 7026 ExecStart=/usr/sbin/rabbitmq-server (code=exited, status=1/FAILURE)
Main PID: 7026 (code=exited, status=1/FAILURE)
Status: "Standing by"
Aug 12 05:47:22 rmq01 systemd[1]: rabbitmq-server.service: main process exited, code=exited, status=1/FAILURE
Aug 12 05:47:22 rmq01 systemd[1]: Failed to start RabbitMQ broker.
Aug 12 05:47:22 rmq01 systemd[1]: Unit rabbitmq-server.service entered failed state.
Aug 12 05:47:22 rmq01 systemd[1]: rabbitmq-server.service failed.
I'm sure the answer is right in front of me but I can't seem to pin point it.
please use the new format file config:
https://github.com/rabbitmq/rabbitmq-server/blob/v3.8.x/deps/rabbit/docs/rabbitmq.conf.example
## Related doc guide: https://rabbitmq.com/access-control.html.
## The default "guest" user is only permitted to access the server
## via a loopback interface (e.g. localhost).
## {loopback_users, [<<"guest">>]},
##
# loopback_users.guest = true

Failed global initialization: FileRenameFailed: Could not rename preexisting log file

I get this error while trying to launch mongo deamon.
CONTROL [main] Failed global initialization: FileRenameFailed: Could
not rename preexisting log file
"/var/lib/mongodb/log/mongod.log" to
"/var/lib/mongodb/log/mongod.log.2021-12-02T14-32-24"; run
with --logappend or manually remove file: Permission denied
config
storage:
dbPath: "/var/lib/mondodb/data"
systemLog:
destination: file
path: "/var/lib/mongodb/log/mongod.log"
mongodb has ownership of /var/lib/mongodb and subdirs. Permissions are supposed to be fine.
mondodb dir
drwxr-xr-x 2 mongodb mongodb 4096 Dec 2 15:42 config
drwxr-xr-x 2 mongodb mongodb 4096 Dec 2 15:41 data
drwxr-xr-x 2 mongodb mongodb 4096 Dec 2 15:42 log
The service itself won't run either
> sudo service mongod status
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2021-12-06 17:09:38 GMT; 1s ago
Docs: https://docs.mongodb.org/manual
Process: 24234 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=100)
Main PID: 24234 (code=exited, status=100)
Dec 06 17:09:37 GEL-R90VQK84 systemd[1]: Started MongoDB Database Server.
Dec 06 17:09:38 GEL-R90VQK84 systemd[1]: mongod.service: Main process exited, code=exited, status=100/n/a
Dec 06 17:09:38 GEL-R90VQK84 systemd[1]: mongod.service: Failed with result 'exit-code'.
You are running the deamon as root?
Check the ownership of the file
/var/lib/mongodb/log/mongod.log

Gunicorn is failing to start with code=exited, status=203/EXEC

Gunicorn works when testing with 0.0.0.0:8000 but failing with the production version below.
Tried switching user:group to myproject:myproject, root:nginx, myproject:nginx nothing working
sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2020-08-30 08:49:57 PDT; 5s ago
Process: 5576 ExecStart=/var/www/myproject/public_py/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/var/www/myproject/public_py/myproject.sock myproject.wsgi:application (code=exited, status=203/EXEC)
Main PID: 5576 (code=exited, status=203/EXEC)
Aug 30 08:49:57 myprojecthost systemd[1]: Started gunicorn daemon.
Aug 30 08:49:57 myprojecthost systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Aug 30 08:49:57 myprojecthost systemd[1]: gunicorn.service: Failed with result 'exit-code'.
gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=nginx
WorkingDirectory=/var/www/myproject/public_py
ExecStart=/var/www/myproject/public_py/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/var/www/myproject/public_py/myproject.sock myproject.wsgi:application
[Install]
WantedBy=multi-user.target
Project lives in /var/www/myproject
cat /var/log/nginx/error.log
[crit] 1198#0: *51 connect() to unix:/var/www/myproject/public_py/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: xx.xxx.xx.xxx, server: myproject.com, request: "GET / HTTP/1.1", upstream: "http://unix:/var/www/myproject/public_py/myproject.sock:/", host: "myproject.com"
stat /var/www/myproject/public_py/env/bin/gunicorn
File: /var/www/myproject/public_py/env/bin/gunicorn
Size: 243 Blocks: 8 IO Block: 4096 regular file
Device: fd01h/64769d Inode: 1066021 Links: 1
Access: (0775/-rwxrwxr-x) Uid: ( 0/ root) Gid: ( 984/ nginx)
Context: unconfined_u:object_r:httpd_sys_content_t:s0
Access: 2020-08-30 08:07:44.939754370 -0700
Modify: 2020-08-29 18:16:27.280494281 -0700
Change: 2020-08-30 08:46:09.047708570 -0700
SOLUTION:
nginx was being blocked via SElinux, to resolve change to permissive.

Systemd service enabled but does not start

I have a custom Spring Boot web application running on a Linux virtual machine. I have a systemd script to start/restart the application.
I have tried changing to WantedBy=default.target and it still does not work. I have tried adding After or Type and still does not work
[Unit]
Description=SpringBootSampleApp
[Service]
WorkingDirectory=/home/mecpro
ExecStop=/usr/bin/sudo /home/mecpro/webapp/webapp-0.0.1-SNAPSHOT.war
ExecStart=/usr/bin/sudo /home/mecpro/webapp/webapp-0.0.1-SNAPSHOT.war
[Install]
WantedBy=multi-user.target
My console screen looks like this
Loaded: loaded (/etc/systemd/system/webapp.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-08-12 13:26:27 UTC; 22ms ago
Main PID: 9104 (sudo)
Tasks: 2 (limit: 4675)
When I run systemctl status webapp.service, I get this
webapp.service - SpringBootSampleApp
Loaded: loaded (/etc/systemd/system/webapp.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-08-12 13:26:27 UTC; 3min 17s ago
Process: 9104 ExecStart=/usr/bin/sudo /home/mecpro/webapp/webapp-0.0.1-SNAPSHOT.war (code=exited, status=2)
Main PID: 9104 (code=exited, status=2)
Aug 12 13:26:28 x01133361 sudo[9104]: /home/mecpro/webapp/webapp-0.0.1-SNAPSHOT.war: 2: /home/mecpro/webapp/webapp-0.0.1-SNAPSHOT.war: Syntax error: "(" unexpected
Aug 12 13:26:27 x01133361 systemd[1]: Started SpringBootSampleApp.
Aug 12 13:26:27 x01133361 systemd[1]: webapp.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Aug 12 13:26:27 x01133361 systemd[1]: webapp.service: Failed with result 'exit-code'.
Aug 12 13:26:27 x01133361 sudo[9104]: root : TTY=unknown ; PWD=/home/mecpro ; USER=root ; COMMAND=/home/mecpro/webapp/webapp-0.0.1-SNAPSHOT.war
Aug 12 13:26:27 x01133361 sudo[9104]: pam_unix(sudo:session): session opened for user root by (uid=0)
Aug 12 13:26:27 x01133361 sudo[9104]: pam_unix(sudo:session): session closed for user root
This is my first question on StackOverflow so kindly excuse if the question is badly formatted. Thanks in advance.

Resources