Getting started with systemd
This document describes simple introduction of systemd
and configuration steps for aah application to accomplish it.
systemd
is an init system that provides many powerful features for starting, stopping, reload configuration and managing processes. Refer to systemd man page.
systemd
consists of two main concepts:
- A unit is a configuration file that describes the properties of the process that user want to run.
- A target is a grouping mechanism that allows systemd to start-up groups of processes at the same time. This happens at every boot as processes are started at different run levels.
Note: Ensure the rights are set correctly and provide ownership to the user you want to use. Here, I'll use the aah
as a user account.
Table of Contents
- Handy
generate
Command - Steps to Configure and Enable
- How to Start, Stop, Restart, Reload and Status
- aahframework.org
systemd
service file
Handy generate
Command
Introduced in v0.10.0 aah CLI. Command generate
is to help developer(s) in thier application development. To generate systemd service file for your aah application-
# Go to application base directory and run
aah generate script --name systemd
# OR shorthand
aah g s -n systemd
Steps to Configure and Enable
- Place your service file at
/etc/systemd/system/
.- For e.g.:
aahwebsite.service
- For e.g.:
- Reload the systemctl configurations.
- Run
sudo systemctl daemon-reload
- Run
- Enabling newly created service file with
systemctl
.- Run
sudo systemctl enable aahwebsite.service
- Run
- Congrats, you have successfully created and enabled your application service in
systemd
.
How to Start, Stop, Restart, Reload and Status
Now let’s see how to utilize the service file. Don’t forget to replace your service file/name with below example commands 😄.
Start your application
sudo systemctl start aahwebsite.service
# OR
sudo service aahwebsite start
Stop your application
sudo systemctl stop aahwebsite.service
# OR
sudo service aahwebsite stop
Restart your application
sudo systemctl restart aahwebsite.service
# OR
sudo service aahwebsite restart
Reload your application
Since v0.10 aah application binary supports hot-reload (to reflect changes done in config, views, i18n, etc) without application restart.
sudo systemctl reload aahwebsite.service
# OR
sudo service aahwebsite reload
Status of your application
sudo systemctl status aahwebsite.service
# OR
sudo service aahwebsite status
aahframework.org systemd
service file
For reference. This is aahframework.org
website service file. aah application deployed at location /home/aah/website
.
# GENERATED BY aah CLI - Feel free to customization it.
# FILE: aahwebsite.service
# DATE: Sat, 19 May 2018 21:34:31 -0700
# DESC: aah application systemd service file
[Unit]
Description=aahwebsite application
After=network.target
[Service]
User=aah
Group=aah
EnvironmentFile=/home/aah/website/env_values
ExecStart=/home/aah/website/bin/aahwebsite run --envprofile prod
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target