Skip to content

Commit 08e5bab

Browse files
committed
Install: add Supervisor and systemd support.
1 parent e4653ec commit 08e5bab

2 files changed

Lines changed: 128 additions & 5 deletions

File tree

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ Table of contents
3838
6. [Javascript and CSS files concatenation and minification](#36-javascript-and-css-files-concatenation-and-minification)
3939
7. [Apache configuration](#37-apache-configuration)
4040
8. [Xinetd configuration](#38-xinetd-configuration)
41-
9. [Configuration file](#39-configuration-file)
41+
9. [Supervisor configuration](#39-supervisor-configuration)
42+
10. [Systemd configuration](#310-systemd-configuration)
43+
11. [Configuration file](#311-configuration-file)
4244
4. [Create your own rules](#4-create-your-own-rules)
4345
1. [Why should you create your own rules?](#41-why-should-you-create-your-own-rules)
4446
2. [Where to put the rule?](#42-where-to-put-the-rule)
@@ -451,7 +453,7 @@ Dispak helps you to manage the static files of your web projects.
451453

452454
There is two (non-mutually exclusive) ways to manage these files: Using symlink, and copying files to Amazon S3.
453455

454-
#### Symbolink links
456+
#### Symbolic links
455457
You can define a list of symbolic links in the [configuration file](#39-configuration-file). These links will be created during the tag installation process. In fact, you define the target of each link (usually a directory but it can be a file), and the directory where these links are giong to be created. The created links are named with the installed version's number.
456458

457459
Example: Let's say your configuration file contains this line:
@@ -479,11 +481,15 @@ Then, you can adapt your templates (see previous section) to use the copied asse
479481

480482
### 3.6 Javascript and CSS files concatenation and minification
481483

482-
Dispak can concatenate and minify Javascript and CSS files, using the [`minifier` program](https://www.npmjs.com/package/minifier) (see [Installation prerequisites](#21-prerequisites) above). The files are generated (concatenated and minified) during the packaging process.
484+
Dispak can concatenate files. The files are generated during the packaging process.
485+
486+
In the [Dispak configuration file](#39-configuration-file), the `CONF_PKG_CONCAT` is an associative array. Each key is the path to the generated file, and the value is a space-separated list of paths to the files to concatenate.
487+
488+
Dispak can also concatenate and minify Javascript and CSS files, using the [`minifier` program](https://www.npmjs.com/package/minifier) (see [Installation prerequisites](#21-prerequisites) above). The files are generated (concatenated and minified) during the packaging process.
483489

484490
In the [Dispak configuration file](#39-configuration-file), the `CONF_PKG_MINIFY` is an associative array. Each key is the path to the generated file, and the value is a space-separated list of paths to the files to concatenate and minify.
485491

486-
If a generated (concatenated and minified) file is version controlled, it is automatically committed after generation. Otherwise it is deleted after the packaging process.
492+
If a generated (concatenated, or concatenated and minified) file is version controlled, it is automatically committed after generation. Otherwise it is deleted after the packaging process.
487493

488494

489495
### 3.7 Apache configuration
@@ -534,7 +540,23 @@ If you manage multiple projects with Dispak, the contents of all their `etc/xine
534540
If you need to generate the crontab file dynamically, you can create an `etc/xinetd.gen` file. This script will be executed (like other [generator scripts](##34-files-generation)) and its output will be used as the xinetd configuration content.
535541

536542

537-
### 3.9 Configuration file
543+
### 3.9 Supervisor configuration
544+
545+
You can add Supervisor configuration files in the `etc/supervisor/` directory. These files must have the extension `.conf`. Dispak will copy them to the `/etc/supervisor/conf.d` directory. This operation is done every time you install a new tagger version, so you just have to keep you configuration files up-to-date. The previous content is replaced by the new files' content.
546+
547+
If a configuration file has the `.conf.gen` extension, it is considered as a file generator. This script will be executed (like other [generator scripts](##34-files-generation)) and its output will be used as the content of the destination file (which name will have the `.conf` extension).
548+
549+
550+
### 3.10 Systemd configuration
551+
552+
You can add file in the `etc/systemd` directory, to add new services that will be managed by systemd.
553+
554+
For a simple service, the configuration file must have the `.service` extension. It will be copied to the `/etc/systemd/system` directory, the service will be enabled and started.
555+
556+
For a target, you must have two files, one with the `.target` extension, the other with the `@.service` extension. They will also be copied to the `/etc/systemd/system` directory. Then the target will be enabled and started.
557+
558+
559+
### 3.11 Configuration file
538560

539561
In a git repository, you can create an `etc/dispak.conf` file. Look at the [`dispak-example.conf`](https://github.com/Digicreon/Dispak/blob/main/dispak-example.conf) example file in the Dispak source repository.
540562

rules/03-install.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ rule_exec_install() {
115115
_install_config_apache
116116
# xinetd configuration
117117
_install_xinetd
118+
# supervisor configuration
119+
_install_supervisor
120+
# systemd configuration
121+
_install_systemd
118122
# files configuration
119123
_install_config_files
120124
# execute post-config scripts
@@ -240,6 +244,103 @@ _install_xinetd() {
240244
echo "$(ansi green)Done$(ansi reset)"
241245
}
242246

247+
# _install_supervisor()
248+
# Install new Supervisor files.
249+
_install_supervisor() {
250+
if [ "${DPK_OPT["no-supervisor"]}" != "" ]; then
251+
return
252+
fi
253+
if [ ! -d "$GIT_REPO_PATH/etc/supervisor" ]; then
254+
return
255+
fi
256+
echo "$(ansi bold)Installing Supervisor configuration$(ansi reset)"
257+
if [ ! -d /etc/supervisor/conf.d ]; then
258+
echo
259+
abort "$(ansi red)Unable to find directory $(ansi reset)/etc/supervisor/conf.d"
260+
fi
261+
CONFIG_FOUND=0
262+
for FILENAME in $GIT_REPO_PATH/etc/supervisor/*; do
263+
if [[ "$FILENAME" == *.conf.gen ]]; then
264+
DEST="/etc/supervisor/conf.d/$(basename "${FILENAME::-4}")"
265+
echo -n "$(ansi dim)+ Generating$(ansi reset) $DEST "
266+
chmod +x "$FILENAME"
267+
sudo bash -c "\"$FILENAME\" \"${DPK_OPT["platform"]}\" \"${DPK_OPT["tag"]}\" > \"$DEST\""
268+
if [ $? -ne 0 ]; then
269+
echo
270+
abort "$(ansi red)Supervisor configuration generation script $(ansi reset)$FILENAME$(ansi red) execution failed.$(ansi reset)"
271+
fi
272+
echo "$(ansi green)done$(ansi reset)"
273+
CONFIG_FOUND=1
274+
elif [[ "$FILENAME" == *.conf ]]; then
275+
DEST="/etc/supervisor/conf.d/$(basename "$FILENAME")"
276+
echo -n "$(ansi dim)+ Copying $(ansi reset) $DEST "
277+
if ! sudo cp "$FILENAME" "$DEST"; then
278+
echo
279+
abort "$(ansi red)Unable to copy file $(ansi reset)$FILENAME$(ansi red) to $(ansi reset)$DEST$(ansi red).$(ansi reset)"
280+
fi
281+
echo "$(ansi green)done$(ansi reset)"
282+
CONFIG_FOUND=1
283+
fi
284+
done
285+
if [ $CONFIG_FOUND -eq 1 ]; then
286+
echo "$(ansi dim)+ Restarting Supervisor$(ansi reset)"
287+
if ! sudo supervisorctl reread || ! sudo supervisorctl update; then
288+
abort "$(ansi red)Unable to restart Supervisor.$(ansi reset)"
289+
fi
290+
echo "$(ansi green)Done$(ansi reset)"
291+
fi
292+
}
293+
294+
# _install_systemd
295+
# Install new systemd files.
296+
_install_systemd() {
297+
if [ "${DPK_OPT["no-systemd"]}" != "" ]; then
298+
return
299+
fi
300+
if [ ! -d "$GIT_REPO_PATH/etc/systemd" ]; then
301+
return
302+
fi
303+
echo "$(ansi bold)Installing systemd configuration$(ansi reset)"
304+
if [ ! -d /etc/systemd/system ]; then
305+
echo
306+
abort "$(ansi red)Unable to find directory $(ansi reset)/etc/systemd/system"
307+
fi
308+
for FILENAME in $GIT_REPO_PATH/etc/systemd/*; do
309+
SERVICE_NAME=""
310+
if [[ "$FILENAME" == "*.target" ]]; then
311+
SERVICE_NAME="$(basename "${FILENAME::-7}")"
312+
echo -n "$(ansi dim)+ Add target$(ansi reset) $SERVICE_NAME "
313+
if [ ! -f "$GIT_REPO_PATH/etc/systemd/$SERVICE_NAME@.service" ]; then
314+
echo
315+
abort "$(ansi red)Unable to find file$(ansi reset) $GIT_REPO_PATH/etc/systemd/$SERVICE_NAME@.service"
316+
fi
317+
if ! sudo cp "$FILENAME" /etc/systemd/system/; then
318+
echo
319+
abort "$(ansi red)Unable to copy file$(ansi reset) $FILENAME $(ansi red)to$(ansi reset) /etc/systemd/system/$SERVICE_NAME.target"
320+
fi
321+
if ! sudo cp "$GIT_REPO_PATH/etc/systemd/$SERVICE_NAME@.service" /etc/systemd/system; then
322+
echo
323+
abort "$(ansi red)Unable to copy file$(ansi reset) $GIT_REPO_PATH/etc/systemd/$SERVICE_NAME@.service $(ansi red)to$(ansi reset) /etc/systemd/system/$SERVICE_NAME@.service"
324+
fi
325+
SERVICE_NAME="$SERVICE_NAME.target"
326+
elif [[ "$FILENAME" == *.service ]] && [[ "$FILENAME" != *@.service ]]; then
327+
SERVICE_NAME="$(basename "${FILENAME::-8}")"
328+
echo -n "$(ansi dim)+ Add service$(ansi reset) $SERVICE_NAME "
329+
if ! sudo cp "$FILENAME" /etc/systemd/system/; then
330+
echo
331+
abort "$(ansi red)Unable to copy file$(ansi reset) $FILENAME $(ansi red)to$(ansi reset) /etc/systemd/system/$SERVICE_NAME.service"
332+
fi
333+
fi
334+
if [ "$SERVICE_NAME" != "" ]; then
335+
if ! sudo systemctl daemon-reload || ! sudo systemctl enable $SERVICE_NAME || ! sudo systemctl start $SERVICE_NAME; then
336+
echo
337+
echo "$(ansi red)Unable to enable or start service$(ansi reset) $SERVICE_NAME $(ansi red).$(ansi reset)"
338+
fi
339+
echo "$(ansi green)done$(ansi reset)"
340+
fi
341+
done
342+
}
343+
243344
# _install_db_migration()
244345
# Do the migration of a new version of the database.
245346
_install_db_migration() {

0 commit comments

Comments
 (0)