A web app hosted locally for wakeonlan
This is a rewrite with sveltekit + PocketBase to replace the old version I wrote a few years ago
In the new rewrite, instead of writing an entire rest API server and manage database with gorm, I use PocketBase as backend and database. Its golang extension feature allows me to add the wakeonlan feature easily. The most complicated part, Auth, is also fully handled by PocketBase, saving lots of time. PocketBase also has a built-in database management UI, making user creation/management much easier.
Deployment with docker is super simple.
Docker image huakunshen/wol
is available on docker hub.
Both linux/amd64
and linux/arm64
are supported.
[!IMPORTANT]
- The container must be in the same network as the target hosts
- The container must be started with
--network=host
- Mac doesn't support
--network=host
with docker. On Mac you have to run server with go directly. It's recommended to use linux.
Here is a full command to start the server with a superuser initialized
docker run --rm \
--network=host \
-e PORT=8090 \
-e SUPERUSER_EMAIL=<[email protected]> \
-e SUPERUSER_PASSWORD=<your password> \
-v ./pb_data:/app/pb_data \
huakunshen/wol:latest
--rm
to clean up the container after it's closed for demo purpose--rm
with -d
to run it in detach modeThe 2 environment variables and volume are optional but recommended.
PORT
environment variable is used to specify the port the server listens on-p
option; thus the PORT
environment variable can be used to change the port.users
collection/table.SUPERUSER_EMAIL
and SUPERUSER_PASSWORD
are set, the server will create this superuser the first time it starts and you could login directly.(!) Launch the URL below in the browser if it hasn't been open already to create your first superuser account:
http://0.0.0.0:8090/_/#/pbinstal/eyJhbGciOiJIUzI1NiIs...
docker run -d
in detach mode, run docker logs <container name>
to find the long URL for superuser creation.The superuser we discussed previously is like a database admin, you need to create a regular user to login to the website.
http://localhost:8090/_/
(or the url of your environment), login with superuser credentialsusers
collection, create a user, remember your email and passwordYou can go to http://localhost:8090/auth
and login with your regular user credentials.
Create a host then you can wake up your computer from browser.
Docker compose makes creating and destroying wol container easier.
A compose.yml is provided in this repo.
services:
wol:
image: "huakunshen/wol"
container_name: wol-web
network_mode: host
volumes:
- wol_data:/app/pb_data
environment:
- [email protected]
- SUPERUSER_PASSWORD=changeme
- PORT=8090
volumes:
wol_data:
docker compose up
docker compose down
Prerequisite:
bun workspace is used to manage this monorepo, dev
script will start frontend and backend together.
bun install
bun run dev # start both sveltekit dev server and golang pocketbase server
The golang server is in apps/server
. It's a golang pocketbase extension with some custom routes.
air # start development
go run main.go serve # start the server without hot reload
When table is modified, run go run . migrate collections
to generate a migration .go
file that will be auto loaded.
The frontend is in apps/web
, written with sveltekit + @sveltejs/adapter-static
.
In development, use http://localhost:5173
.
Running bun run build
will generate a apps/web/build
directory,
and will be automatically copied to apps/server/pb_public
ready to be served directly by the golang server as static assets.
In production the website is accesssible at http://localhost:8090/
.
make buildx
automatically builds docker image for linux/amd64
and linux/arm64
and push to dockerhub.