A simple web application built using Go that allows you to manage some functionalities of your Raspberry Pi without the need of a terminal. The application serves an HTML page with buttons to perform various actions, such as rebooting the Raspberry Pi.
- Web-based interface
- Reboot Raspberry Pi with a button click
- Easy to extend with more buttons and functionalities
- Serves static files for JavaScript and other assets
- Can be run as a daemon service on Raspberry Pi
This Go application is organized to keep HTML templates, JavaScript functions, and server-side handlers separate. You can easily add more buttons and functionalities by following these steps:
- Add a new button with an onclick event handler in the HTML template in the serveHTML function.
- Define a new JavaScript function for the button's onclick event in the main.js file.
- Create a new server-side handler function in the main.go file, if required.
- Register the new handler function with a URL path in the main() function.
To make the Go app run automatically when the Raspberry Pi restarts, you can create a systemd service. Here are the steps:
- Build your Go application, if you haven't done so already:
go build main.go
- Move the compiled binary to a suitable location, like /usr/local/bin:
sudo mv main /usr/local/bin/pi-admin-app
- Create a systemd service file for your application by creating a new file /etc/systemd/system/pi-admin-app.service:
sudo nano /etc/systemd/system/pi-admin-app.service
- Add the following contents to the service file:
[Unit]
Description=Raspberry Pi Control Panel Web Server
After=network.target
[Service]
User=root
Group=root
ExecStart=/usr/local/bin/pi-admin-app
Restart=on-failure
[Install]
WantedBy=multi-user.target
This configuration specifies that the service should start after the network target is reached, run as root, and restart if the process fails. Adjust the User and Group fields if you want to run the service under a different user.
- Reload the systemd configuration:
sudo systemctl daemon-reload
- Enable the service to start on boot:
sudo systemctl enable pi-admin-app.service
- Start the service:
sudo systemctl start pi-admin-app.service
- Check the status of the service:
sudo systemctl status pi-admin-app.service