Update Section_05/main.sh, Section_05/systemd.sh, Section_05/app.js, Section_05/test-node-process.service

This commit is contained in:
Kishan Takoordyal 2023-05-19 18:08:41 +00:00
parent becdbc9586
commit 9aff32ff83
4 changed files with 62 additions and 0 deletions

14
Section_05/app.js Normal file
View File

@ -0,0 +1,14 @@
const http = require('http');
const hostname = '127.0.0.1';
const port = 5000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World! 🐧\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});

34
Section_05/systemd.sh Normal file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# Install NodeJS
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# Place app.js
cd ~/
mkdir tmpNodeApp/
cd tmpNodeApp/
nano app.js
# Start a node process
node app.js
# Check to see if it's working properly in another shell
curl http://localhost:5000
sudo lsof -i -P -n | grep 5000
# Stop process, perform check again
# Create the service file along with running other systemd commands
sudo nano /etc/systemd/system/test-node-process.service
sudo systemctl daemon-reload
sudo systemctl enable --now test-node-process
# Some more typical systemd commands
# sudo systemctl status test-node-process
# sudo systemctl enable test-node-process
# sudo systemctl disable test-node-process
# sudo systemctl start test-node-process
# sudo systemctl stop test-node-process
# sudo systemctl restart test-node-process

View File

@ -0,0 +1,14 @@
[Unit]
Description=Test Node Process
Documentation=https://api.konnect.dev/
After=network.target
[Service]
Type=simple
User=edgeking810
WorkingDirectory=/home/edgeking810/tmpNodeApp/
ExecStart=node app.js
Restart=always
[Install]
WantedBy=multi-user.target