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
- Steps to Configure and Enable
- How to Start, Stop, Restart, Reload and Status
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
- For e.g.:
- For e.g.:
- Reload the systemctl configurations.
sudo systemctl daemon-reload
- Enabling newly created service file with
sudo systemctl enable aahwebsite.service
- Congrats, you have successfully created and enabled your application service in
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
systemd service file
For reference. This is
aahframework.org website service file. aah application deployed at location
# 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