Skip to content
Snippets Groups Projects

spawn-fcgi systemd example

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Jochem Kossen

    Example systemd configuration for spawn-fcgi using a systemd template unit

    Edited
    etc/spawn-fcgi/php-cgi.conf 81 B
    USERID="php-cgi"
    GROUPID="php-cgi"
    FCGIPORT=33169
    FCGIPROGRAM="/usr/bin/php-cgi"
    spawn-fcgi.service 212 B
    [Unit]
    Description=spawn-fcgi spawns FCGI processes
    Documentation=man:spawn-fcgi(1)
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/libexec/spawn-fcgi_launcher %i
    
    [Install]
    WantedBy=multi-user.target
    usr/libexec/spawn-fcgi_launcher 1.04 KiB
    #!/bin/sh
    
    if [ -z "$1" ]; then
        echo "Usage: $0 configuration_file"
        exit 1
    fi
    
    # Config file
    CONF_FILE="/etc/spawn-fcgi/${1}.conf"
    
    # ABSOLUTE path to the spawn-fcgi binary
    SPAWNFCGI="/usr/bin/spawn-fcgi"
    
    # Read settings from config file if it exists
    [ -e "${CONF_FILE}" ] && . "${CONF_FILE}"
    
    if [ -z "$USERID" ]; then
        echo "USERID not set"
        exit 1
    fi
    
    if [ -z "$GROUPID" ]; then
        echo "USERID not set"
        exit 1
    fi
    
    if [ -z "$FCGIPORT" ]; then
        echo "FCGIPORT not set"
        exit 1
    fi
    
    if [ -z "$FCGIPROGRAM" ]; then
        echo "FCGIPROGRAM not set"
        exit 1
    fi
    
    # Check user existence
    if [ ! $(id -u ${USERID} &> /dev/null) ]; then
        echo ;
        echo "User ${USERID} does not exist! Check what you use the correct USERID."
        exit 1
    fi
    
    # Check group existence
    if [ ! $(id -g ${GROUPID} &> /dev/null) ]; then
        echo ;
        echo "Group ${GROUPID} does not exist! Check what you use the correct GROUPID."
        exit 1
    fi
    
    # Execute spawn-fcgi with its options
    env - ${SPAWNFCGI} -p ${FCGIPORT} -f ${FCGIPROGRAM} -u ${USERID} -g ${GROUPID}
    
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment