source: project/wiki/spiffy-systemd-scripts @ 36676

Last change on this file since 36676 was 31173, checked in by anonymous, 5 years ago

Add spiffy-systemd-scripts

File size: 2.7 KB
Line 
1Here's an example systemd script for [[/egg/spiffy|Spiffy the webserver]], for use on systems using the systemd daemon manager.
2
3Systemd requires two files to be placed in two different locations:
4
5* A plain text script file named "spiffy"
6* A plain text service file named "spiffy.service"
7
8Be sure to make both files executable and owned by root.
9
10The spiffy file, to be placed in /usr/lib/systemd/scripts/
11
12<enscript highlight="shell">
13#! /bin/sh
14# -*- shell-script -*-
15
16# This is /etc/init.d/spiffy on Linux systems using systemd
17# It assumes you have a "spiffy.scm" script in /usr/local/libexec and a log directory in /var/log/spiffy
18
19# Select which "csi" program to use; defaults to the one in $PATH
20CSI=csi
21# Use a longer trace buffer and a larger nursery size (optional)
22CSI_ARGS="-:s1m -:a200"
23
24DATE_FORMAT="+%Y-%m-%d %H:%M:%S"
25
26CONFIG_FILE="/usr/local/libexec/spiffy.scm"
27LOG_DIR="/var/log/spiffy"
28
29start() {
30 if [ ! -d "$LOG_DIR" ]; then
31      echo "Log directory \"$LOG_DIR\" does not exist."
32      exit 1
33    fi
34
35    if [ ! -r "$CONFIG_FILE" ]; then
36      echo "Cannot find or read the configuration file. Please create or check the permissions of the following file: \"$CONFIG_FILE\"."
37      exit 1
38    fi
39
40    echo "Starting spiffy..."
41    echo "start: " `date "$DATE_FORMAT"` >> /var/log/spiffy/start-stop.log
42    (cd /var/log/spiffy; ulimit -c unlimited ; $CSI $CSI_ARGS -s /usr/local/libexec/spiffy.scm &)  </dev/null &> /var/log/spiffy/init.log
43}
44
45stop() {
46    echo "Stopping spiffy..."
47    echo "stop: " `date "$DATE_FORMAT"` >> /var/log/spiffy/start-stop.log
48    pids=`ps ax | grep "[/]usr/local/libexec/spiffy.scm" | awk '{print $1}'`
49    if [ -z "$pids" ] ; then
50       echo "spiffy is not running"
51    else
52        for pid in $pids; do
53            echo "killing " $pid
54            kill $pid
55        done
56    fi
57}
58case "$1" in
59    start)
60        start
61        ;;
62    stop)
63        stop
64        ;;
65    restart)
66        stop
67        sleep 1
68        start
69        ;;
70    *) exit 1
71esac
72</enscript>
73
74The spiffy.service file, to be placed in /usr/lib/systemd/system/
75
76<enscript highlight="shell">
77[Unit]
78Description=Spiffy the webserver
79
80[Service]
81Type=oneshot
82ExecStart=/usr/lib/systemd/scripts/spiffy start
83ExecStop=/usr/lib/systemd/scripts/spiffy stop
84RemainAfterExit=yes
85
86[Install]
87WantedBy=multi-user.target
88</enscript>
89
90Now you can start, stop or restart Spiffy using the following commands:
91
92<enscript highlight="shell">$ systemctl start spiffy</enscript>
93<enscript highlight="shell">$ systemctl stop spiffy</enscript>
94<enscript highlight="shell">$ systemctl restart spiffy</enscript>
95
96To enable Spiffy to be started at boot:
97
98<enscript highlight="shell">$ systemctl enable spiffy</enscript>
Note: See TracBrowser for help on using the repository browser.