# miniserve



## bangmyhead (Sep 20, 2022)

Hello, I want to share in a very easy way, files on my local network by using http. I have installed miniserve, but I can not find any documentation of how to use it.


----------



## jbo (Sep 20, 2022)

Without actually looking too deep into it, it would seem that the only documentation available is the readme from the code repository: https://github.com/svenstaro/miniserve

This illustrates how to use it.

Note: It seems that the FreeBSD port is slightly out of date. You might want to open a PR for that


----------



## K5KGT (Sep 20, 2022)

What a neat little find.  Only minor issued fixed from 0.20->0.21->0.22 so the 0.20 should work ok till it's brought current by port maintainer.  

Looks to be a quick way to pull things around the house/lab from computer to computer on an ad-hock basis.  Point it a a directory on the "server", pull the file, Ctrl-C and it's off.


----------



## bangmyhead (Sep 21, 2022)

It works awesome but its there any way to make it permanent? I mean to auto start when computer starts? Like in rc.conf or something like that?


----------



## jbo (Sep 21, 2022)

You can create an rc.d script which daemonizes any executable. This would allow for the service to be auto-started as well as being automatically being restarted if it crashes.

I left a few notes regarding that in my blog a while ago: https://blog.insane.engineer/post/freebsd_daemonize


----------



## bangmyhead (Sep 21, 2022)

jbodenmann said:


> You can create an rc.d script which daemonizes any executable. This would allow for the service to be auto-started as well as being automatically being restarted if it crashes.
> 
> I left a few notes regarding that in my blog a while ago: https://blog.insane.engineer/post/freebsd_daemonize




```
#!/bin/sh
# PROVIDE: miniserver
# REQUIRE: networking
# KEYWORD:

. /etc/rc.subr

name="miniserve"
rcvar="miniserve_enable"
miniserve_user="miniserve"
miniserve_command="/usr/local/bin/miniserve"
pidfile="/var/run/miniserve/${name}.pid"
command="/usr/sbin/miniserve"
command_args="-P ${pidfile} -r -f ${miniserve_command}"

load_rc_config $name
: ${miniserve_enable:=no}

run_rc_command "$1"
```

I just made it like this, its ok or it needs some corrections?


----------



## bangmyhead (Sep 21, 2022)

Also, could it be set in crontab? As for example:


```
@reboot /usr/local/bin/miniserve share/
```


----------



## jbo (Sep 21, 2022)

bangmyhead said:


> Also, could it be set in crontab? As for example:


Sure, that _might_ work too.
Usually, rc.d would be the preferred option here as the OS then "knows" about the service. You can ask it to start it, to stop it, you can query the status, PID and so on.
Furthermore, you get control over when the service is being started. For example, you can ensure that your miniserve service is not started before networking is up & running etc.


----------



## bangmyhead (Sep 21, 2022)

jbodenmann said:


> Sure, that _might_ work too.
> Usually, rc.d would be the preferred option here as the OS then "knows" about the service. You can ask it to start it, to stop it, you can query the status, PID and so on.
> Furthermore, you get control over when the service is being started. For example, you can ensure that your miniserve service is not started before networking is up & running etc.


Thanks but I do not know if I wrote the script ok or not


----------



## bangmyhead (Sep 21, 2022)

And I have another question, can I set for example the .exe files to direct execute from the server instead of download it? Because if I click on it right now it download the file only.


----------



## jbo (Sep 21, 2022)

bangmyhead said:


> Thanks but I do not know if I wrote the script ok or not


I'm no rc.d expert. I'd argue, if this is your first rodeo, the question would be: does it do what you want?



bangmyhead said:


> And I have another question, can I set for example the .exe files to direct execute from the server instead of download it? Because if I click on it right now it download the file only.


I haven't really looked at miniserve but as far as I can tell it's a simple HTTP server. Therefore, any file being served is just that: A file being served over an HTTP response.
Executing a binary on the host would require something like CGI or RPC. That's a whole different beast/story. At that point you might be better of using something like www/nginx or similar. But neither CGI nor RPC will just magically work. In case of CGI, your binary needs to have a CGI interface.
As far as I can tell, miniserve's purpose is to _share files_. Nothing more, nothing less.


----------



## bangmyhead (Sep 21, 2022)

bangmyhead said:


> Also, could it be set in crontab? As for example:
> 
> 
> ```
> ...


Ok, this one worked.


----------

