Skip to content

Commit 6fd44c0

Browse files
authored
[plugins] Use relative paths or env variables in configs DEV-1272 (#382)
## Summary @Lagoja called out that we were using absolute paths in conf files. Since the conf files are checked-in, they need to be env variables or relative paths if the file doesn't support env variables. I also added `services restart` which really helped me test this out. ## How was it tested? ``` devbox add nginx apacheHttpd php devbox services start curl localhost curl localhost:8080 curl localhost:8080/index.php ```
1 parent 220f6e5 commit 6fd44c0

File tree

7 files changed

+33
-9
lines changed

7 files changed

+33
-9
lines changed

internal/boxcli/services.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@ func ServicesCmd() *cobra.Command {
4949
},
5050
}
5151

52+
restartCommand := &cobra.Command{
53+
Use: "restart [service]...",
54+
Short: "Restarts service. If no service is specified, restarts all services",
55+
RunE: func(cmd *cobra.Command, args []string) error {
56+
return restartServices(cmd, args, flags)
57+
},
58+
}
59+
5260
flags.config.register(servicesCommand)
5361
servicesCommand.AddCommand(lsCommand)
62+
servicesCommand.AddCommand(restartCommand)
5463
servicesCommand.AddCommand(startCommand)
5564
servicesCommand.AddCommand(stopCommand)
5665
return servicesCommand
@@ -118,3 +127,12 @@ func serviceNames(box devbox.Devbox) ([]string, error) {
118127
}
119128
return names, nil
120129
}
130+
131+
func restartServices(
132+
cmd *cobra.Command,
133+
services []string,
134+
flags servicesCmdFlags,
135+
) error {
136+
_ = stopServices(cmd, services, flags)
137+
return startServices(cmd, services, flags)
138+
}

internal/plugin/pkgcfg.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (m *Manager) CreateFilesAndShowReadme(pkg, rootDir string) error {
7171
}
7272
var buf bytes.Buffer
7373
if err = t.Execute(&buf, map[string]string{
74+
"DevboxConfigDir": rootDir,
7475
"DevboxDir": filepath.Join(rootDir, devboxDirName, pkg),
7576
"DevboxDirRoot": filepath.Join(rootDir, devboxDirName),
7677
"DevboxProfileDefault": filepath.Join(rootDir, nix.ProfilePath),
@@ -144,6 +145,7 @@ func buildConfig(pkg, rootDir, content string) (*config, error) {
144145
}
145146
var buf bytes.Buffer
146147
if err = t.Execute(&buf, map[string]string{
148+
"DevboxConfigDir": rootDir,
147149
"DevboxDir": filepath.Join(rootDir, devboxDirName, pkg),
148150
"DevboxDirRoot": filepath.Join(rootDir, devboxDirName),
149151
"DevboxProfileDefault": filepath.Join(rootDir, nix.ProfilePath),

plugins/apache/httpd.conf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ LoadModule alias_module modules/mod_alias.so
2626
Require all denied
2727
</Directory>
2828

29-
DocumentRoot "{{ .DevboxDirRoot }}/web"
30-
<Directory "{{ .DevboxDirRoot }}/web">
29+
DocumentRoot "${HTTPD_CONFDIR}/../web"
30+
<Directory "${HTTPD_CONFDIR}/../web">
3131
Options Indexes FollowSymLinks
3232
AllowOverride None
3333
Require all granted
@@ -36,7 +36,7 @@ DocumentRoot "{{ .DevboxDirRoot }}/web"
3636
<Files ".ht*">
3737
Require all denied
3838
</Files>
39-
ErrorLog "${HTTPD_CONFDIR}/error.log"
39+
ErrorLog "${HTTPD_ERROR_LOG_FILE}"
4040
<IfModule headers_module>
4141
RequestHeader unset Proxy early
4242
</IfModule>
@@ -46,9 +46,9 @@ ErrorLog "${HTTPD_CONFDIR}/error.log"
4646
ServerName php_localhost
4747

4848
UseCanonicalName Off
49-
DocumentRoot "{{ .DevboxDirRoot }}/web"
49+
DocumentRoot "${HTTPD_CONFDIR}/../web"
5050

51-
<Directory "{{ .DevboxDirRoot }}/web">
51+
<Directory "${HTTPD_CONFDIR}/../web">
5252
Options All
5353
AllowOverride All
5454
<IfModule mod_authz_host.c>
@@ -57,7 +57,7 @@ ErrorLog "${HTTPD_CONFDIR}/error.log"
5757
</Directory>
5858

5959
## Added for php-fpm
60-
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:8082/{{ .DevboxDirRoot }}/web/$1
60+
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:8082/${HTTPD_DEVBOX_CONFIG_DIR}/devbox.d/web/$1
6161
DirectoryIndex index.html
6262

6363
</VirtualHost>

plugins/apacheHttpd.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "0.0.1",
44
"readme": "If you with to edit the config file, please copy it out of the .devbox directory.",
55
"env": {
6+
"HTTPD_DEVBOX_CONFIG_DIR": "{{ .DevboxConfigDir }}",
67
"HTTPD_CONFDIR": "{{ .DevboxDir }}",
8+
"HTTPD_ERROR_LOG_FILE": "{{ .Virtenv }}/error.log",
79
"HTTPD_PORT": "8080"
810
},
911
"create_files": {

plugins/nginx/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ server {
44
listen 80;
55
listen [::]:80;
66
server_name localhost;
7-
root {{ .DevboxDirRoot }}/web;
7+
root ../../../devbox.d/web;
88

99
error_log error.log error;
1010
access_log access.log;

plugins/php.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"match": "^php[0-9]*$",
55
"readme": "PHP is compiled with default extensions. If you would like to use non-default extensions you can add them with devbox add php81Extensions.{extension} . For example, for the memcache extension you can do `devbox add php81Extensions.memcached`.",
66
"env": {
7+
"PHPFPM_ERROR_LOG_FILE": "{{ .Virtenv }}/php-fpm.log",
8+
"PHPFPM_PID_FILE": "{{ .Virtenv }}/php-fpm.log",
79
"PHPFPM_PORT": "8082"
810
},
911
"create_files": {

plugins/php/php-fpm.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[global]
2-
pid = {{ .Virtenv }}/php-fpm.pid
3-
error_log = {{ .Virtenv }}/php-fpm.log
2+
pid = ${PHPFPM_PID_FILE}
3+
error_log = ${PHPFPM_ERROR_LOG_FILE}
44
daemonize = yes
55

66
[www]

0 commit comments

Comments
 (0)