How to install upstart
This article revisits essentials on how to install upstart
an event based daemon for starting/stopping tasks on development and production servers.
This article has complementary materials to the Testing
nodejs
Applications book. However, the article is designed to help both those who already bought the book, as well as the wide audience of software developers to setup working environment. You can grab a copy of this book on this link
There are a plethora of task execution solutions, for instance systemd
and init
, rather complex to work with. That makes upstart a good alternative to such tools.
In this article you will learn about:
—
- Tools available for task execution
- How to install
upstart
task execution - How to write basic
upstart
task
Installing upstart
on Linux
It is always a good idea to update the system before start working. There is no exception, even when a daily task updates automatically binaries. That can be achieved on Ubuntu and Aptitude enabled systems as following:
$ apt-get update # Fetch list of available updates
$ apt-get upgrade # Upgrades current packages
$ apt-get dist-upgrade # Installs only new updates
Example: updating aptitude binaries
At this point most of packages should be installed or upgraded. Except Packages whose PPA have been removed or not available in the registry. Installing software can be done by installing binaries, or using Ubuntu package manager.
Installing a upstart
on Linux using apt
Installing upstart
on macOS
upstart
is a utility designed mainly for Linux systems. However, macOS has its equivalent, launchctl
designed to stop/stop processes prior/after the system restarts.
Installing upstart
on a Windows machine
Whereas macOS systems and Linux are quite relax when it comes to working with system processes, Windows is a beast on its own way. upstart
was built for *nix
systems but there is no equivalent on Windows systems: Service Control Manager. It basically has the same ability to check and restart processes that are failing.
Automated upgrades
Before we dive into automatic upgrades, we should consider nuances associated to managing a mongodb
instance. The updates fall into two major, quite interesting, categories: patch updates and version upgrades.
Following the SemVer ~ aka Semantic Versioning standard, it is recommended that the only pair minor versions be considered for version upgrades. This is because minor versions, as well as major versions, are subject to introducing breaking changes or incompatibility between two versions. On the other hand, patches do not introduce breaking changes. Those can therefore be automated.
In case of a critical infrastructure piece of processes state management calibre, we expect breaking changes when a new version introduces a configuration setting is added, or dropped between two successive versions. Upstart provides backward compatibility, so chances for breaking changes between two minor versions is really minimal.
We should highlight that it is always better to upgrade at deployment time. The process is even easier in containerized context. We should also automate only patches, to avoid to miss security patches.
In the context of Linux, we will use the unattended-upgrades package to do the work.
$ apt-get install unattended-upgrades apticron
Example: install unattended-upgrades
Two things to fine-tune to make this solution work are: to enable a blacklist of packages we do not to automatically update, and two, to enable particular packages we would love to update on a periodical basis. That is compiled in the following shell scripts.
Unattended-Upgrade::Allowed-Origins {
// "${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security"; # upgrading security patches only
// "${distro_id}:${distro_codename}-updates";
// "${distro_id}:${distro_codename}-proposed";
// "${distro_id}:${distro_codename}-backports";
};
Unattended-Upgrade::Package-Blacklist {
"vim";
};
Example: fine-tune the blacklist and whitelist in /etc/apt/apt.conf.d/50unattended-upgrades
The next step is necessary to make sure unattended-upgrades download, install and cleanups tasks have a default period: once, twice a day or a week.
APT::Periodic::Update-Package-Lists "1"; # Updates package list once a day
APT::Periodic::Download-Upgradeable-Packages "1"; # download upgrade candidates once a day
APT::Periodic::AutocleanInterval "7"; # clean week worth of unused packages once a week
APT::Periodic::Unattended-Upgrade "1"; # install downloaded packages once a day
Example: tuning the tasks parameter /etc/apt/apt.conf.d/20auto-upgrades
This approach works on Linux(Ubuntu), especially deployed in production, but not Windows nor macOS. The last issue, is to be able to report problems when an update fails, so that a human can intervene whenever possible. That is where the second tool apticron
in first paragraph intervenes. To make it work, we will specify which email to send messages to, and that will be all.
EMAIL="<email>@<host.tld>"
Example: tuning reporting tasks email parameter /etc/apticron/apticron.conf
Conclusion
In this article we revisited ways to install upstart
on various platforms. Even though configuration was beyond the scope of this article, we managed to get everyday quick refreshers out.
References
- An A-Z Index of the Apple macOS command line (macOS bash) and the Apple macOS How-to guides and examples
- Configuring
nodejs
applications
#nodejs #homebrew #UnattendedUpgrades #nginx #y2020 #Jan2020 #HowTo #ConfiguringNodejsApplications #tdd #TestingNodejsApplications