diff --git a/Section_05/app.js b/Section_05/app.js new file mode 100644 index 0000000..0ed4dce --- /dev/null +++ b/Section_05/app.js @@ -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}/`); +}); diff --git a/Section_04/main.sh b/Section_05/main.sh similarity index 100% rename from Section_04/main.sh rename to Section_05/main.sh diff --git a/Section_05/systemd.sh b/Section_05/systemd.sh new file mode 100644 index 0000000..a1a9e88 --- /dev/null +++ b/Section_05/systemd.sh @@ -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 diff --git a/Section_05/test-node-process.service b/Section_05/test-node-process.service new file mode 100644 index 0000000..e97a247 --- /dev/null +++ b/Section_05/test-node-process.service @@ -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