hacdias / caddy-v1-service Goto Github PK
View Code? Open in Web Editor NEW:black_large_square: Run Caddy as a service
Home Page: https://caddyserver.com/docs/hook.service
License: Apache License 2.0
:black_large_square: Run Caddy as a service
Home Page: https://caddyserver.com/docs/hook.service
License: Apache License 2.0
Please add a "-service status" command.
Thank you.
Total n00b here, so be gentle. Had a tough enough time to get caddy to start (every guide on Windows said use .txt for the caddyfile, and that doesn't work when you want it to start without parameterizing the config location...but I digress).
Following your guides (and for reference, I was using the command prompt as administrator), and got the service to install, but not start through the CLI. When i went in through the GUI and told the service to run as Administrator and provided the credentials it started. Of course, running this as a lower privileged user would be preferred - Is this an issue in my configuration of caddy or in the caddy-service that I had to privilege the service accordingly?
Any help's appreciated!
Side question (further exposing my n00b nature, sorry - I assume there's a good reason for this) - in the readme,md, is there a reason you don't specifically call out the -conf parameter, even though it's required for install?
Would it be better to potentially read as follows?:
Install a Caddy service:
caddy -service install -conf pathToConfiguration [-name optionalServiceName] [-option optionValue]
I mean, technically it seems like -conf is an optional parameter, but should it be? Or would making it a required parameter mean you have to provide it for every reference to -service?
Hello!
I start command caddy -service start
in folder on production server, but service don't start.
I don't get warning message and service caddy don't start. If I do write command caddy -host mysite.com
in my work folder on production server, it everything works. How to diagnostic my problem?
Thanks for answer.
For my service, I am required to use a specific working dir and a specific user. Using caddy-service, there is no way to configure this. I have to manually edit the systemd file and add my extra WorkingDirectory=
and User=
arguments. I would like to request the ability to add arguments to the service file created (such as these to start) so I do not have to manually edit the systemd file and can use caddy-service as wrapper to this functionality.
Do I need to set it on "/etc/environment" (because this is not worked for me) or elsewhere?
Thanks
Hi!
Hopefully the solution to this is pretty simple. It won't start as a service, and fails with this in the Event Viewer:
The Caddy service terminated with service-specific error Incorrect function..
When installing the service I am using the following:
C:\caddy>caddy.exe -service install -conf C:\caddy\Caddyfile
Am I doing something wrong here?
Reproduction steps:
Install the service:
sudo caddy -service install -conf /home/user/Caddyfile -email [email protected] -agree -log /var/log/caddy.log
Try to start the service:
sudo service Caddy start
Service status:
sudo service Caddy status
● Caddy.service - Caddy's service
Loaded: loaded (/etc/systemd/system/Caddy.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Fri 2018-04-06 17:14:22 UTC; 2s ago
Process: 9481 ExecStart=/usr/local/bin/caddy -agree true -conf /home/user/Caddyfile -email [email protected] -log /var/log/caddy.log (code=exited, status=1/FAILURE)
Main PID: 9481 (code=exited, status=1/FAILURE)
When running the ExecStart
command by hand you get:
args:2 - Error during parsing: Unknown directive 'true'
It's easy to fix by hand by editing the ExecStart
key in /etc/systemd/system/Caddy.service
but a slight annoyance.
The on shutdown event doesnt run if included in caddyfile related to #25
Hey!
I noticed singularity in settings Caddyfile.
When I write this syntax - everything is working:
localhost:8080 {
root /Users/root/workflow/site
}
if I write this syntax:
localhost:8080 {
root ~/workflow/site
}
I get 404 error.
This subtlety not described in docs.
Thanks for reading =)
(centos 7)
Install caddy
curl https://getcaddy.com | bash -s hook.service,http.git
Then
caddy -service install
so,where is my Caddyfile?
Howdy,
On Ubuntu 16.04
I'd like to run caddy as an unprivileged user. If I add a caddy user and add a Caddyfile to /home/caddy/Caddyfile, I can easily start caddy as that user and point it to my config. I'm just doing the old nohup trick now, but I'd feel better if Caddy was a service and would start on boot.
However, I don't quite get how I can do this - this plugin seems to be what I want, but I've tried many a command without sucess (essentially, I can start the service, but can't figure out how to tell it to start as caddy user nor how to point it to my config file)
I apologize beforehand for any n00bish-ness here :)
Steps to reproduce:
Expected behavior:
Caddy should report the invalid state and exit immediately
Actual results:
Caddy starts running web service as if the -service flag hadn't been passed
This was specifically tested on Windows 10 but probably misbehaves similarly on other OSes.
Analysis: I haven't written anything in golang yet, but my guess is the if block following err = service.Control(s, action)
should do an os.Exit(1)
after printing the err to stderr rather than returning the err to the Caddy hook invoker.
caddy -service start Caddy
where is Caddyfile?
When I set up a folder for my website with a Caddyfile, and then caddy -service install
, the generated /etc/systemd/system/Caddy.service should include the -root parameter or set the WorkingDirectory so that the service finds my folder and the Caddyfile.
Right now, this service ignores my Caddyfile and starts up with the default config (http://:2015
).
if hook.service is build into caddy using current master if caddy is run from command line in windows and then stopped by ctrl-c the following panic happens
panic: close of closed channel
goroutine 81 [running]:
github.com/mholt/caddy/vendor/github.com/mholt/certmagic.(*Cache).Stop(...)
D:/godev/src/github.com/mholt/caddy/vendor/github.com/mholt/certmagic/cache.go:87
github.com/mholt/caddy/caddytls.NewConfig.func1(0x10694f0, 0xc0420cc340)
D:/godev/src/github.com/mholt/caddy/caddytls/config.go:105 +0x35
github.com/mholt/caddy.(*Instance).ShutdownCallbacks(0xc04223c000, 0xc0420cc340, 0xc0420cc340, 0x0)
D:/godev/src/github.com/mholt/caddy/caddy.go:169 +0xba
github.com/mholt/caddy.allShutdownCallbacks(0xbf02d0, 0x8, 0xad3bc0)
D:/godev/src/github.com/mholt/caddy/sigtrap.go:100 +0x114
github.com/mholt/caddy.executeShutdownCallbacks.func1()
D:/godev/src/github.com/mholt/caddy/sigtrap.go:80 +0x96
sync.(*Once).Do(0x1097820, 0xc042007f88)
C:/Go/src/sync/once.go:44 +0xc5
github.com/mholt/caddy.executeShutdownCallbacks(0xbed72f, 0x6, 0x0)
D:/godev/src/github.com/mholt/caddy/sigtrap.go:76 +0x7a
github.com/mholt/caddy.trapSignalsCrossPlatform.func1.1()
D:/godev/src/github.com/mholt/caddy/sigtrap.go:66 +0x3d
created by github.com/mholt/caddy.trapSignalsCrossPlatform.func1
D:/godev/src/github.com/mholt/caddy/sigtrap.go:65 +0xe3
In discussion @mholt thought perhaps
It looks like they're calling ShutdownCallbacks too, but the Ctrl+c handler does this already
I'm using caddy service combined with a plugin that I'm creating to run other processes continuously while caddy is running.
My plugin subscribes to caddy onShutdown, but when the service stops it doesn't call ShutdownCallbacks.
Do you see any issues with invoking ShutdownCallbacks on service stop?
I did implement it and it works fine on windows, I will open a PR soon to share the code with you.
Hi and awesome work on this buddy. Here is some feedback about my experience to see if this helps with a couple of deployment issues.
If I may, I think I see several minor issues here that when using -service install should be addressed to make it easier for faster deployment. When using the hook.service, caddy -service install should do the following to fix several issues at once:
When it creates the service (using systemd for example) it should also create a default folder for the SSL certificates and a default for the caddyserver file. Like /etc/caddy/ssl for the ssl files and /etc/caddy for the conf file. (As a bonus it should by default be renamed to caddy.service, not Caddy.service (Capital C there).
The default conf folder is to avoid having to guess or manually add the conf parameter.
The default ssl folder is to avoid having several issues when doing the whole systemd process as a it fails if it cant find the folders.
There should be a default log in /var/log/caddy (default with option to set somewhere else, same for conf and ssl folders).
Did not check but an option to automatically restart if the caddyserver file is updated or changed (same option to check if caddyserver file has correct format, if not, do not restart service but send a warning to the logs. If all is good, automatically restart service)
This are just a couple of things that would help in deployment.
I've read in the Caddy documentation that it can be reloaded with the signal USR1
, here I quote:
USR1
Reloads the configuration file, then gracefully restarts the server.
If there is an error with the new configuration, the error is logged and the configuration
rolls back with zero downtime.
Since the caddy -service restart [-name optionalName]
only takes the optional argument name I suppose I can't pass that signal here.
In this answer an approach is suggested, however, while peeking around service.go
I didn't understand how the restart is handled. And in case if such method can be implemented.
I can run the service with this command
caddy103 -service start -name CaddyServerT -log d:\caddy\logs\service.log
However when I go to any of the sites I have configured I get an error. I dont seem to be able to get any logs as the log file is never created.
All the domains are local dns linked (eg resolve to 127.0.0.1) but I can't see how that is relevant. I can serve the sites with Caddy without -service using the same Caddyfile.
I am running on Windows 10.
I know this is pretty vague, but any pointers would be appreciated.
Caddy shuts down after printing error on 'service' hook: No service system detected.
to the log
This issue is copy from caddyserver/caddy#2331 as suggested by @mholt
caddy -version
)?Caddy 0.11.0
Try to stop/restart Caddy after change configuration file on Windows Server 2008 but it did not stop.
https://example.com {
gzip
push
tls C:/caddy/certs/example.crt C:/caddy/certs/example.key {
ciphers ECDHE-ECDSA-AES128-GCM-SHA256 ECDHE-RSA-AES128-GCM-SHA256 ECDHE-ECDSA-WITH-CHACHA20-POLY1305 ECDHE-RSA-WITH-CHACHA20-POLY1305 ECDHE-RSA-AES128-CBC-SHA ECDHE-ECDSA-AES128-CBC-SHA RSA-AES128-CBC-SHA
curves X25519 p256
}
header / {
X-XSS-Protection "1; mode=block"
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
Strict-Transport-Security "max-age=31536000;"
-Server
-X-Powered-By
}
proxy / http://example.com {
transparent
}
}
caddy -service install -quic -conf c:\caddy\Caddyfile -name caddy
and start/stop Caddy using Administrative Tools > Services
I have tried to run with command line by open cmd.exe and run caddy.exe directly and found this problem happen after Caddy run for a while and there is connection open with the client, if you press Ctrl+C, Caddy didn't response to kill signal and leave caddy.exe running (Caddy did not receive new connection anymore after your press Ctrl+C on console, just running and you need to restart server to make it run again).
N/A
Can stop/restart Caddy without problem
There is no error log, Caddy just failed to stop and leave caddy.exe process that could not be killed and finally need to restart server to make Caddy run and receive connection again.
N/A
Downloading a new build from https://caddyserver.com/download and including only the hook.service plugin, extracting to C:/caddy/, then creating a service using caddy.exe -service install -conf Caddyfile
(and the Caddyfile only contains localhost:80), I am not able to start the service. The event log shows an error with the message:
The Caddy service terminated with the following service-specific error:
Incorrect function.
Full event data:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Service Control Manager" Guid="{555908d1-a6d7-4695-8e1e-26931d2012f4}" EventSourceName="Service Control Manager" />
<EventID Qualifiers="49152">7024</EventID>
<Version>0</Version>
<Level>2</Level>
<Task>0</Task>
<Opcode>0</Opcode>
<Keywords>0x8080000000000000</Keywords>
<TimeCreated SystemTime="2017-11-01T13:28:20.355603800Z" />
<EventRecordID>8154</EventRecordID>
<Correlation />
<Execution ProcessID="1076" ThreadID="24728" />
<Channel>System</Channel>
<Computer>laptop</Computer>
<Security />
</System>
<EventData>
<Data Name="param1">Caddy</Data>
<Data Name="param2">%%1</Data>
<Binary>430061006400640079000000</Binary>
</EventData>
</Event>
Tested on Windows 10 Creators Update as well as Fall Creators Update. Tried with logging as well, but it looks like the executable never runs at all.
Tested 32 and 64 bit, both fail the same way.
When running the same Caddy build normally in a console, it works fine.
Hi there,
First, thanks for making this extension, it's great. I just had the following symptoms, and wasn't sure if it was a bug, or just needed to be documented (in which case, I can submit a PR with a change).
On Windows 10, x64, I am able to run Caddy and have it load my caddyfile, which specifies to listen on port 8005. When I run Caddy manually, everything works and it listens on 8005 only.
I was able to install and start the service with the default command: caddy.exe -service install
and caddy.exe -service start
. The service also appears in Windows services manager as started, and I can interact with it there too. But Caddy isn't listening on 8005 in that case. Through some inspection, I saw that Caddy was listening on its default 2015 instead. When I uninstalled the service and reinstalled it with caddy.exe -service install -conf path\to\my\CaddyFile
everything worked as expected. Caddy listened on 8005 and not 2015. the CaddyFile is in the same folder as caddy.exe, so I would expect the default to be that it picks up the CaddyFile.
My CaddyFile is simple, in case it's relevant:
:8005/static {
tls off
log ./caddy_access.log
errors visible
root C:/Code/icefish_backend/icefish/static
}
Is this expected behavior, or is this a bug? If it's expected, would you be open to a PR making the behavior clearer? Thanks again for the extension!
Running Windows Server 2016; I own my own SSL for my domain so I shouldn't need -agree and -email for LetsEncrypt (not using it.)
The configuration works when run manually.
Installed the services with cmd-line:
caddy -service install -conf C:\Caddy\Caddyfile -log C:\Caddy\ServiceRun.log
Attempts to start results in "incorrect function" in Event Viewer, no Caddy log is created.
If I leave out the conf file, it does start but (obviously) doesn't use the correct conf.
conf file contents:
mega.mydomain.com {
proxy / 127.0.0.1:5000 {
transparent
}
tls C:\caddy\_mydomain_com.crt C:\caddy\_mydomain_com.key
}
I did see the other thread outlining this issue but having the -agree and e-mail flags don't help.
I recently downloaded 0.10.14 and now 0.11 and included the Service plugin.
Any command set to run on startup
is not run.
hello.azure.cookingisfun.ie:8080 {
tls off
on startup "myfile.bat" &
}
If I run 0.11 without the service plugin included the myfile.bat file is executed. Perhaps @elcore might be able to help track down where the issue is.
I am using windows.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.