Tag: Linux
One can absolutely run Python code in the cloud with low/zero cost, and existing VPS is actually the best option for persistent (“daemon”) execution. Below is a detailed comparison of all options, with clear recommendations based on your scenario.
β Existing VPS is the PERFECT Solution (Zero Cost Beyond Existing Server)
Since you already have a VPS with Python installed, this is the most cost-effective and reliable option for running code as a daemon. No new costs, full control, and no cloud vendor limitations.
Spoiler: Step by Step setup at VPS.
How to Run as a Daemon on Your VPS:
- Use
systemd
(Modern Linux – Recommended)
Create a service file (e.g.,/etc/systemd/system/myapp.service
):
[Unit]
Description=My Python App
After=network.target
[Service]
User=youruser
WorkingDirectory=/path/to/your/app
ExecStart=/usr/bin/python3 /path/to/your/app/main.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Then:
sudo systemctl enable myapp # Auto-start on boot
sudo systemctl start myapp # Start now
Centos 7, Node.js, MySQL connect
I’ve mariadb installed on my VDS with Centos 7.
I’ve installed mysql npm package:
npm i mysql
Yet requesting that package with
var mysql = require('mysql');
has not provided to the successful connection.
While
var mysql = require('mariadb');
has done.
var mysql = require('mariadb');
var con = mysql.createConnection({
host: "localhost",
user: "admin_default",
password: "xxxxxx",
database: 'admin_default'
}).then(function (){
console.log('connected!');
}, function(err){
console.log(err);
});
//console.log(con);
Problem
I’ve made a simple node.js server at VDS:
var http = require('http');
http.createServer(function (req, res) {
let port = 9999;
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(post, '0.0.0.0');
console.log('Server running at port ' + port);
It works outputting:
Server running at port 9999
yet I can’t reach it at VPS/VDS IP where the code is residing: http://webscraping.pro:9999/ How to solve that?
Given:
- host: lx567.certain.com (SFTP)
- user: igor_user
- password: testPass
For SSH access in a terminal type:
$ ssh igor_user@lx567.certain.com
then enter the password (testPass) at a password prompt.
My Linux Tips
I created this post just to have a place where to keep all those linux things I always forget π Hope you’ll find it useful for you as well.