A problem with running my python script on a Linux VPS - bots

I'm trying to deploy my telegram bot on a linux VPS. I've uploaded the python script to the VPS, but if I run it through python3 bot_name command nothing seems to happen because when put in ps aux command my bot doesn't show in the processes list. I used systemctl to ensure that the bot works 24/7, but when I type in systemctl status bot_name it says the following: enter image description here
So it seems to me that it constantly crashes and then restarts immediately but no error message shows up when I run the script. What can be done to fix this?

Related

Crontab won't launch Node.js Discord bot on Ubuntu

I have a bot running on an Ubuntu machine which I'd like to autorun on boot, and so I'm using crontab's #reboot scheduled line for it:
#reboot ~/Bot/run
It works perfectly for all other scripts I have running on boot on my machine, but for this specific script, every line is seemingly being executed correctly, except for the one involving the actual node . command, which launches my Discord bot. The script works perfectly fine when I run it myself from a terminal. Here's the script in question, run.sh, very simple and short in nature:
#!/bin/bash
cd ~/Bot
echo "Launching Discord Bot"
screen -dmS BOT node .
To sum it up, I first enter the correct working directory, send a basic echo, then create a new detached screen session called BOT, to which I pass the node . command, in which the period . implies the index.js file found in my bot's directory. And yes, I intend the screen session to automatically close if/when the bot's process stops.
As mentioned, it seems to actually run the script as intended, but just failing to launch the node.js server. I've tried adding other test lines to the script, including one that sends a message to said Discord server using a webhook, and it correctly sends the messages when placed before and after the node . line.
I've been troubleshooting this for a little while, and I've tried adding a task as a system service in /etc/systemd/system instead of using Crontab, to no avail. I've also tried setting the cronjob to use a login shell with bash -lc to set the proper environment variables for Crontab, still to no avail. I'm all out of solutions, would anyone know how to solve this issue?

Run mlagents_envs UnityEnvironment from remote ssh login

I have a script in which I build a mlagents_envs.environments.UnityEnvironment that successfully launches and works when I run the script from terminal sessions started on my ubuntu machine (that has a GUI). And if I ssh into the machine, I can run these scripts from tmux sessions that were originally created locally on my machine. If, however, I try to run the script from a terminal session created through the remote ssh connection, the script hangs when trying to create the UnityEnvironment. It just says:
Found path: <path_to_unity_executable>
and eventually times out.
I've tried to run the script with a virtual display and it still doesn't work. Specifically, I've tried:
$ xvfb-run --auto-servernum --server-args='-screen 1 640x480x24:64' python3 python_script.py -batchmode
$ xvfb-run --auto-servernum --server-args='-screen 1 640x480x24:64' python3 python_script.py
And I've tried the instructions found here: https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Training-on-Amazon-Web-Service.md
Has anyone encountered this issue? Do you have any suggestions?
The solution ended up being fairly simple. I just needed to specify the right DEVICE before running the script.
$ DEVICE=:1 python3 python_script.py
If anyone else runs into this, you might also need to enable X11 forwarding in both the ssh settings on the server and the client. I'm not 100% sure.

npm ping is opening command prompt windows

I want to ping certain IPs in a project, and I am using npm ping package for this.
https://www.npmjs.com/package/ping
When I run the service, its running fine. But when is run my service in the PM2, the command prompt windows are showing up, each time the ping action is done in that service(I am pinging in loops to monitor an IP).
What is the reason for this and please suggest an alternative solution.
The same problem happened to me while using forever to run my script in background.
I've found that using START /B node script.js on windows instead of forever worked just fine and the command prompt didn't showed up. I don't know much about PM2 but maybe you should be able to prefix your command with START /B somewhere in PM2 or just run your script by yourself.

#reboot via crontab isnt working

IM running a VPS server on Ubuntu 14.04 minimal x86. I connect to it using putty via SSH.
On the server i have a simple script that is starting a few instances of bots
nohup node /nodebots/bot10/server.js &
I use root as a user, so all the privileges and +chmod X are set properly (in my opinion)
The idea is that my node.js program is not excelent + the service im running the bots for sometimes has reboots, server crashes etc.
Ive installed crontab and at this moment struggling to set the script to be run at boot.
Ive used various solutions including trying to boot it via init.d , adding a line to rc.local and well using crontab -e. None of it helps.
Currently the code in crontab looked the following ways
`#reboot sh /nodebots/botsrun.sh`
#reboot root /nodebots/sh botsrun.sh
#reboot cd /nodebots/ && sh botsrun.sh
None of it helped.
Im new to Ubuntu, coding and even terminal commands. I would really apreaciate any kind of help. I will be more then grateful for a step by step tutorial on what im doing wrong and what should be done.

How to start application after login on CentOS?

I am trying to start GUI application with upstart script on CentOS. I have test script located /etc/init/ folder.
start on desktop-session-start
stop on desktop-shutdown
respawn
script
export DISPLAY=:0
sleep 5
exec /.1/Projects/UpstartTest/start.sh &
end script
start.sh scripts is running binary files for GUI application.
After reboot my computer. When I typed:
[root#mg-CentOS ~]# initctl status test
test stop/waiting
So my upstart is not runnig. When i type
initctl start test
manually it works fine without any problem.
How can I run this upstart script after user login (desktop started) ? I am trying to find detailed documents for CentOS for upstart but there is no.
For this purpose, you can use the update-rc tool, which is builtin on linux distributions. It basically creates a symbolic link for the script you want to be executed at startup, or some other OS states, on the folder rc.X, where X is the number of the folder that determines a state that you want.
You may want to have a look at this answer: Update-rc.d custom script running too late, and also runs at shutdown
More information about can be found here:
http://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts
Detailed information about the CentOS booting process can be found here: https://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-boot-init-shutdown-process.html;
the rc is being explained at this document as well.

Resources