How do I run a docker container declaratively on nixos server ? I am trying to run whoogle on a nix server and I don't wish to manually restart the whoogle container everytime I restart the server.
After bit of guidance from the r/nixos community settled with this.
{ config, pkgs, ... }:
let
host = "mydomain";
in
{
virtualisation = {
podman = {
enable = true;
dockerCompat = true;
};
oci-containers = {
backend = "podman";
containers.whoogle-search = {
image = "benbusby/whoogle-search";
autoStart = true;
ports = [ "8080:5000" ]; #server locahost : docker localhost
};
};
};
services.nginx.virtualHosts = {
"search.${host}" = {
enableACME = true;
forceSSL = true;
locations."/".proxyPass = "http://localhost:8080";
};
};
}
Use --restart always with docker command at initial start
enable docker service to start at boot
And your container will start at boot
I have installed moodle in AWS EC2 instance. But config.php file is missing. And I created a file using **
touch config.php
** command. But I couldnt place my content inside that file.
My content is
<?php // Moodle configuration file
unset($CFG); global $CFG; $CFG = new stdClass();
$CFG->dbtype = 'mariadb'; $CFG->dblibrary = 'native'; $CFG->dbhost
= 'localhost'; $CFG->dbname = 'moodledb'; $CFG->dbuser = 'root'; $CFG->dbpass = 'pass'; $CFG->prefix = 'mdl_'; $CFG->dboptions = array ( 'dbpersist' => 0, 'dbport' => '', 'dbsocket' => '', 'dbcollation' => 'utf8mb4_general_ci', );
$CFG->wwwroot = 'http://localhost/moodle'; $CFG->dataroot = 'L:\\xampp\\moodledata'; $CFG->admin = 'admin';
$CFG->directorypermissions = 0777;
require_once(__DIR__ . '/lib/setup.php');
I have connected to AWS using Putty from windows.
Use cat and heredoc:
cat > config.php <<'EOF'
your content
goes here
EOF
And you can skip touch this way.
I'm a bit stuck with my server deployment recipes...
So far, I can create and provision my servers via commandline:
First I run salt-cloud and afterwards I provision it via salt-ssh...
But since I'm using some special ports (https,...) I also have to set/open input/endpoints (=ports) on Microsoft Azure.
This is where I stuck: is there any way of telling salt-cloud, to automatically execute a script, which opens the endpoints automatically?
My preferred result would be:
run salt-cloud => sets up new machine and opens all necessary ports
run salt-ssh to provision them
I have already looked at salt orchestration, but it looks like it's more for server fleets, instead of single (external) server configuration.
Any hints?
You could write a custom bootstrap script that would open the ports that you want.
As Utah_Dave said, I wrote a ruby script to add the ports...
# ruby
# execute with ruby startscript.rb
require 'json'
PROVIDER = "yourprovider"
SERVER = "yourserver"
ENDPOINTS = {
"SSH2" => 17532,
"HTTPS" => 443,
"HTTP" => 80,
"SlangerHTTP" => 8080,
"Slanger" => 4567,
"CouchDB" => 5984
}
def get_missing
service_existing = false
while !service_existing
begin
res = `salt-cloud --out=json -f list_input_endpoints #{PROVIDER} deployment=#{SERVER} service=#{SERVER}`
result = JSON.parse(res)
service_existing = true
rescue => e
puts e
end
end
existing_services = result[PROVIDER]["azure"].keys
missung_services = ENDPOINTS.keys - existing_services
end
missung_services = get_missing
while missung_services.any?
print "#{Time.now} [#{SERVER}] Services missing: #{missung_services.join(", ")}"
missung_services.each do |m|
print "."
`salt-cloud --out=json -f add_input_endpoint #{PROVIDER} name=#{m} port=#{ENDPOINTS[m]} protocol=tcp deployment=#{SERVER} service=#{SERVER} role=#{SERVER}`
end
print "\n"
missung_services = get_missing
end
I have a server.js file defined as follows:
var iniparser = require('iniparser');
var inihost;
var inidbuser;
var inidbpass;
var inidbname;
var config = iniparser.parseSync('../setup_db/config.ini');
inihost = config.db_hostname;
inidbuser=config.db_username;
inidbpass=config.db_password;
inidbname=config.db_name;
.....
on reboot I have a crontab that should automatically forever starts the server:
#reboot /usr/bin/sudo /usr/local/bin/forever start /var/www/html/rubrica/chat/server.js
Interestingly if I launch the server from any directory with the complete path like:
forever start /var/www/html/rubrica/chat/server.js
the server starts just fine..if , however, i run the SAME command from withtin the /root/.forever/ directory the server will give me the following error:
ENOENT, no such file or directory '../setup_db/config.ini'
So whenever i reboot the machine I get that error...how is such a thing possible?
The argument to iniparser.parseSync() is not relative to the current file like require() but rather the current working directory. Use:
var path = require('path');
var config = iniparser.parseSync(path.join(__dirname, '../setup_db/config.ini'));
I am here because I am trying to use Couchbeam form my page on a YAWS.
I have tested CB and it worked correctly from Terminal, using:
erl -pa ebin -pa deps/ibrowse/ebin -s couchbeam
Now I am trying to replicate what I did locally on my webpage.
I believe the issue is that I don't know how to tell erl to do 'erl -pa ebin -pa deps/ibrowse/ebin -s couchbeam' from a yaws page.
I have tried to simply running all the needed apps, but I am getting this:
Stack: [{ibrowse_lib,url_encode,["test"],[]},
{couchbeam,save_doc,3,[{file,"src/couchbeam.erl"},{line,383}]},
{m50,out,1,
[{file,"/Users/Nesh/.yaws/yaws/default/m50.erl"},{line,35}]},
{yaws_server,deliver_dyn_part,8,
[{file,"yaws_server.erl"},{line,2647}]},
{yaws_server,aloop,4,[{file,"yaws_server.erl"},{line,1152}]},
{yaws_server,acceptor0,2,[{file,"yaws_server.erl"},{line,1013}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]
This is my erl code:
<erl>
startApp() ->
application:start(crypto),
application:start(private_key),
application:start(ssl),
application:start(sasl),
application:start(ibrowse),
application:start(couchbeam).
out(Arg) ->
startApp(),
Host = "localhost",
Port = 5984,
Prefix = "",
Options = [],
S = couchbeam:server_connection(Host, Port, Prefix, Options),
Options = [],{ok, Db} = couchbeam:open_db(S, "erlang", Options),
Doc = {[{<<"_id">>, <<"test">>},{<<"content">>, <<"web text">>}]},
{ok, Doc1} = couchbeam:save_doc(Db, Doc).
</erl>
I wouldn't recommend running Couchbeam from within a .yaws page like this. You should instead either create an Erlang release such that Couchbeam and Yaws are both executed within the same Erlang VM and then use a Yaws appmod to call into Couchbeam, or maybe you should consider making Couchbeam a bootstrap yapp for Yaws.
If you really think you're having load path problems, you can specify load paths in the yaws.conf file via the ebin_dir directive. For example:
ebin_dir = deps/ibrowse/bin
ebin_dir = couchbeam/ebin
But the stack trace you show seems like it's missing something, so it's hard to tell you exactly what's wrong.
I managed to fix it doing this:
I've added these lines in yaws.conf:
ebin_dir = /usr/local/var/yaws/couchbeam/deps/ibrowse/ebin
ebin_dir = /usr/local/var/yaws/couchbeam/deps/jiffy/ebin
ebin_dir = /usr/local/var/yaws/couchbeam/deps/mochiweb/ebin
ebin_dir = /usr/local/var/yaws/couchbeam/ebin
Note: I put the folder 'couchbeam' in /usr/local/var/yaws/
then I modified the code in this way:
load_deps() ->
application:start(sasl),
application:start(ibrowse),
application:start(jiffy),
application:start(inets),
application:start(xmerl),
application:start(compiler),
application:start(syntax_tools),
application:start(mochiweb),
application:start(couchbeam).
out(Arg) ->
load_deps(),
Host = "localhost",
Port = 5984,
Prefix = "",
Options = [],
S = couchbeam:server_connection(Host, Port, Prefix, Options),
Options = [],{ok, Db} = couchbeam:open_db(S, "erlang", Options),
Doc = {[{<<"content">>, <<"Checking webpage">>}]},
{ok, Doc1} = couchbeam:save_doc(Db, Doc),
{html, "Document has been added"}.
</erl>