Can i auto start caddy in windows 10

Sorry i,m a total newbie is there away of auto starting caddy in widows 10 just in case my computer restarts.
Can some one show me to make a .bat file for windows for this.

You could create a scheduled task that runs on startup only, or place a shortcut of the starting script on the Startup directory.

2 Likes

Hi Mike,

When I first started deploying Go web services last year internally, the first Go application I deployed was Gogs.

This was fortunate for me, since while reading up on it’s installation instructions:

It mentioned this tool called the “Non Sucking Service Manager” for Windows:
https://nssm.cc/

And since then I’ve been using it for Caddy as well to have it startup automatically as a service when our Windows servers startup too.

Overall it works really well (the only issues I’ve had have been related to changes in Caddy over the past year so sometimes copying over the new Caddy binary, or making adjustments to the Caddyfile, cause the service not to startup properly, but that can be checked by stopping the service, running Caddy at the command line to see the output, and then figuring out the problem and then going back to the service and starting it back up normally afterward…after that though things are normally fine).

hi what would the start up script look like or how do i go about this im a total newbie.

Hey @jbravo2uk,

If you’re looking at using NSSM, there’s a pretty comprehensive doc here: NSSM - the Non-Sucking Service Manager

Should give you all the info you need. You can download it here: NSSM - the Non-Sucking Service Manager

sorry im still having problems can anyone show me a start up script which i could possibly convert into a .bat file ?

If you just want a script that will run Caddy.exe, all you really need is a single START command in a .bat file:

https://ss64.com/nt/start.html

sorry i am still haveing problems can someone show me what the script line should look like please.
I have my caddy in my c drive.
sorry to be a pain.

this is what i have in my .bat file (@echo off
"C:\Caddy\caddy)but it only shows this screen please see image.

You should be able to use the new hook.service plugin. Download the latest copy of Caddy with hook.service included as a plugin (its right down the bottom of the list).

I have written up a helpful example of how to use it on windows, it hasnt been merged yet so thats why I have to lik to the PR

The main thing to note is you must include the full path to your caddyfile and specify you log file in the initial call to caddy -service install

eg

caddy -service install -conf="C:\Caddy\Caddyfile" -log "C:\Caddy\ServiceRun.log"

Caddy is then installed as a service and can be autostarted on startup like any other service.

2 Likes

Thank you very much its all running like it should.

You just got my hopes up… i was thinking Service = Daemon, and the docs page doesn’t mention anywhere that this is windows only.

(I’ve had some issues with Caddy and systemd that i hoped would be solved by this. I guess i’ll wait for official support then)

I dont think it is windows only, but perhaps @hacdias might clarify.

Hello @Nichlas,

As @tobya said, this plugin is not Windows-only. It is stated in the documentation:

Right now, this plugin seems to work well on most systems that kardianos/service supports, which are Windows XP+, Linux/(systemd | Upstart | SysV), and OSX/Launchd.

:slight_smile:

看见你这样子说我突然想起了一个软件,它叫做"nssm"版本是2.24.
不知道是否能实现比BAT更加好的效果呢?!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.