2. Running Services
Last updated
Last updated
Before we start installing and running our services, it is good to keep our system up to date. To update our system, do:
nginx
is a great web server for these things, but you can pick whatever you want, or are more familiar with
On Ubuntu, this is pretty simple: apt install nginx
Enable it and start it: sudo systemctl enable nginx
, sudo systemctl start nginx
Open up your browser and head to http://host/ — you should see a page there
Edit files in /var/www/html/..., etc: try replacing index.html? with "hello world"
check http://host/ again
Here's a pretty cool, simple website. Let's try and deploy it:
One of the best things about a server is that it's meant to run 24/7, something that our laptops or desktops aren't great at doing. This means it's really good at running things constantly at a scheduled interval. To do such a thing, we'll use something known as cron jobs.
Cron is a scheduling daemon that executes tasks at specified intervals.
These tasks are called cron jobs and are mostly used to automate system maintenance or administration.
The crontab command allows you to install, view , or open a crontab file for editing:
crontab -e
- Edit crontab file, or create one if it doesn’t already exist.
crontab -l
- Display crontab file contents.
crontab -r
- Remove your current crontab file.
crontab -i
- Remove your current crontab file with a prompt before removal.
crontab -u
- Edit other user crontab file. This option requires system administrator privileges.
We have an API that gives us the 24 hour weather forecast in Singapore. We want to:
Check this forecast every morning
If it's about to rain, send us an alert. For simplicity, lets send a telegram message!
Here's a bash script that sends a telegram message if it's going to rain that day:
To get a telegram bot id, just go to @BotFather, and create a new bot, enter the token we receive inside
To get your chat id, just go to @getmyid_bot and copy your chat id there
You'll need to start a chat with your bot first, go to your bot and do '/start' before you try running the script
Here are some more local APIs you can try to automate/script!
These should give you a very simple idea of hosting some services on our own servers. There's so much more we can't cover in a 2 hour workshop but here are some resources if you're fast/want to learn more!
Syncthing is an open-source file synchronization tool that allows you to effortlessly synchronize files across multiple devices. It runs on various platforms, providing a seamless experience for syncing files securely and privately over local networks or the internet.
There are plenty of reasons why you should never use or trust public VPN providers. We can set up our own to ensure that we can browse the internet securely or hide our IP addresses by routing our network traffic through our servers instead.