Web and Backend daemon: watch config, same uid/gid as file
This commit is contained in:
		| @@ -4,45 +4,12 @@ use strict; | ||||
| use warnings FATAL => 'all'; | ||||
| use 5.010_000; | ||||
|  | ||||
| use File::ShareDir 'dist_dir'; | ||||
| use Path::Class; | ||||
|  | ||||
| our $VERSION = '2.024004'; | ||||
|  | ||||
| BEGIN { | ||||
|   if (not ($ENV{DANCER_APPDIR} || '') | ||||
|       or not -f file($ENV{DANCER_APPDIR}, 'config.yml')) { | ||||
|  | ||||
|       my $auto = dir(dist_dir('App-Netdisco'))->absolute; | ||||
|       my $home = ($ENV{NETDISCO_HOME} || $ENV{HOME}); | ||||
|  | ||||
|       $ENV{DANCER_APPDIR}  ||= $auto->stringify; | ||||
|       $ENV{DANCER_CONFDIR} ||= $auto->stringify; | ||||
|  | ||||
|       my $test_envdir = dir($home, 'environments')->stringify; | ||||
|       $ENV{DANCER_ENVDIR} ||= (-d $test_envdir | ||||
|         ? $test_envdir : $auto->subdir('environments')->stringify); | ||||
|  | ||||
|       $ENV{DANCER_ENVIRONMENT} ||= 'deployment'; | ||||
|       $ENV{PLACK_ENV} ||= $ENV{DANCER_ENVIRONMENT}; | ||||
|  | ||||
|       $ENV{DANCER_PUBLIC} ||= $auto->subdir('public')->stringify; | ||||
|       $ENV{DANCER_VIEWS}  ||= $auto->subdir('views')->stringify; | ||||
|   } | ||||
|  | ||||
|   { | ||||
|       # Dancer 1 uses the broken YAML.pm module | ||||
|       # This is a global sledgehammer - could just apply to Dancer::Config | ||||
|       use YAML; | ||||
|       use YAML::XS; | ||||
|       no warnings 'redefine'; | ||||
|       *YAML::LoadFile = sub { goto \&YAML::XS::LoadFile }; | ||||
|   } | ||||
| } | ||||
|  | ||||
| # set up database schema config from simple config vars | ||||
| use App::Netdisco::Environment; | ||||
| use Dancer ':script'; | ||||
|  | ||||
| # set up database schema config from simple config vars | ||||
| if (ref {} eq ref setting('database')) { | ||||
|     my $name = (setting('database')->{name} || 'netdisco'); | ||||
|     my $host = setting('database')->{host}; | ||||
|   | ||||
							
								
								
									
										40
									
								
								Netdisco/lib/App/Netdisco/Environment.pm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								Netdisco/lib/App/Netdisco/Environment.pm
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| package App::Netdisco::Environment; | ||||
|  | ||||
| use strict; | ||||
| use warnings FATAL => 'all'; | ||||
|  | ||||
| use File::ShareDir 'dist_dir'; | ||||
| use Path::Class; | ||||
|  | ||||
| BEGIN { | ||||
|   if (not ($ENV{DANCER_APPDIR} || '') | ||||
|       or not -f file($ENV{DANCER_APPDIR}, 'config.yml')) { | ||||
|  | ||||
|       my $auto = dir(dist_dir('App-Netdisco'))->absolute; | ||||
|       my $home = ($ENV{NETDISCO_HOME} || $ENV{HOME}); | ||||
|  | ||||
|       $ENV{DANCER_APPDIR}  ||= $auto->stringify; | ||||
|       $ENV{DANCER_CONFDIR} ||= $auto->stringify; | ||||
|  | ||||
|       my $test_envdir = dir($home, 'environments')->stringify; | ||||
|       $ENV{DANCER_ENVDIR} ||= (-d $test_envdir | ||||
|         ? $test_envdir : $auto->subdir('environments')->stringify); | ||||
|  | ||||
|       $ENV{DANCER_ENVIRONMENT} ||= 'deployment'; | ||||
|       $ENV{PLACK_ENV} ||= $ENV{DANCER_ENVIRONMENT}; | ||||
|  | ||||
|       $ENV{DANCER_PUBLIC} ||= $auto->subdir('public')->stringify; | ||||
|       $ENV{DANCER_VIEWS}  ||= $auto->subdir('views')->stringify; | ||||
|   } | ||||
|  | ||||
|   { | ||||
|       # Dancer 1 uses the broken YAML.pm module | ||||
|       # This is a global sledgehammer - could just apply to Dancer::Config | ||||
|       use YAML; | ||||
|       use YAML::XS; | ||||
|       no warnings 'redefine'; | ||||
|       *YAML::LoadFile = sub { goto \&YAML::XS::LoadFile }; | ||||
|   } | ||||
| } | ||||
|  | ||||
| 1; | ||||
| @@ -36,6 +36,18 @@ but they are backwards compatible. | ||||
|  | ||||
| =back | ||||
|  | ||||
| =head1 2.025000 | ||||
|  | ||||
| =head2 General Changes | ||||
|  | ||||
| The Web and Backend daemons (C<netdisco-web> and C<netdisco-daemon> | ||||
| respectively) will now watch your C<deployment.yml> configuration file, and | ||||
| restart themselves whenever it is changed. | ||||
|  | ||||
| The Web and Backend daemons will also now drop privilege to the same user and | ||||
| group as their files on disk. This allows you to symlink the programs as | ||||
| run-control scripts, yet maintain non-root privilege status. | ||||
|  | ||||
| =head1 2.023000 | ||||
|  | ||||
| =head2 Incompatible Changes | ||||
|   | ||||
		Reference in New Issue
	
	Block a user