| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | [Unit] | 
					
						
							|  |  |  | Description=Caddy HTTP/2 web server | 
					
						
							|  |  |  | Documentation=https://caddyserver.com/docs | 
					
						
							|  |  |  | After=network-online.target | 
					
						
							|  |  |  | Wants=network-online.target systemd-networkd-wait-online.service | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [Service] | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # Restart on crash (bad signal), but not on 'clean' failure (error exit code) | 
					
						
							|  |  |  | # Allow up to 3 restarts within 10 seconds | 
					
						
							|  |  |  | # (it's unlikely that a user or properly-running script will do this) | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | Restart=on-abnormal | 
					
						
							|  |  |  | StartLimitInterval=10 | 
					
						
							|  |  |  | StartLimitBurst=3 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # User and group the process will run as | 
					
						
							|  |  |  | # (www-data is the de facto standard on most systems) | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | User=www-data | 
					
						
							|  |  |  | Group=www-data | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # Letsencrypt-issued certificates will be written to this directory. | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | Environment=CADDYPATH=/etc/ssl/caddy | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # Always set "-root" to something safe in case it gets forgotten in the Caddyfile. | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | WorkingDirectory=/etc/ssl/caddy | 
					
						
							|  |  |  | ExecStart=/usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp | 
					
						
							|  |  |  | ExecReload=/bin/kill -USR1 $MAINPID | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # Limit the number of file descriptors and processes; see `man systemd.exec` for more limit settings. | 
					
						
							|  |  |  | # Unmodified caddy is not expected to use more than this. | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | LimitNOFILE=1048576 | 
					
						
							|  |  |  | LimitNPROC=64 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # Use private /tmp and /var/tmp, which are discarded after caddy stops. | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | PrivateTmp=true | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # Use a minimal /dev | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | PrivateDevices=true | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # Hide /home, /root, and /run/user. Nobody will steal your SSH-keys. | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | ProtectHome=true | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # Make /usr, /boot, /etc and possibly some more folders read-only. | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | ProtectSystem=full | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # … except /etc/ssl/caddy, because we want Letsencrypt-certificates there | 
					
						
							|  |  |  | #   and /var/log/caddy, because we want a place where logs can go. | 
					
						
							|  |  |  | #   This merely retains r/w access rights, it does not add any new. Must still be writable on the host! | 
					
						
							|  |  |  | ReadWriteDirectories=/etc/ssl/caddy /var/log/caddy | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Note: in v231 and above ReadWritePaths has been renamed to ReadWriteDirectories | 
					
						
							|  |  |  | ; ReadWritePaths=/etc/ssl/caddy /var/log/caddy | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # The following additional security directives only work with systemd v229 or later. | 
					
						
							|  |  |  | # They further retrict privileges that can be gained by caddy. | 
					
						
							|  |  |  | # Note that you may have to add capabilities required by any plugins in use. | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | CapabilityBoundingSet=CAP_NET_BIND_SERVICE | 
					
						
							|  |  |  | AmbientCapabilities=CAP_NET_BIND_SERVICE | 
					
						
							|  |  |  | NoNewPrivileges=true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 12:28:55 -06:00
										 |  |  | # Caveat: Some plugins need additional capabilities. | 
					
						
							|  |  |  | # For example "upload" needs CAP_LEASE | 
					
						
							|  |  |  | ; CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_LEASE | 
					
						
							|  |  |  | ; AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_LEASE | 
					
						
							|  |  |  | ; NoNewPrivileges=true | 
					
						
							| 
									
										
										
										
											2017-04-20 18:04:57 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | [Install] | 
					
						
							|  |  |  | WantedBy=multi-user.target |