This repository has been archived by the owner on Oct 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1518b57
commit dc47d2f
Showing
8 changed files
with
155 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module aim.daemon.commands; | ||
|
||
private | ||
{ | ||
import jaster.cli; | ||
import aim.common, aim.deploy, aim.secrets, aim.daemon; | ||
} | ||
|
||
@Command("daemon run", "Runs the program in daemon mode.") | ||
final class AimDaemonRun : BaseCommand | ||
{ | ||
private AimDaemon _daemon; | ||
|
||
this(AimDaemon daemon) | ||
{ | ||
this._daemon = daemon; | ||
} | ||
|
||
override int onExecute() | ||
{ | ||
this._daemon.runForeverLoop(); | ||
return 0; | ||
} | ||
} | ||
|
||
@Command("daemon watch", "Register the current directory as a deployment project to the daemon.") | ||
final class AimDaemonWatch : BaseCommand | ||
{ | ||
private IAimCliConfig!AimDaemonConfig _config; | ||
|
||
this(IAimCliConfig!AimDaemonConfig config) | ||
{ | ||
this._config = config; | ||
} | ||
|
||
override int onExecute() | ||
{ | ||
import std.algorithm : canFind; | ||
import std.file : getcwd; | ||
|
||
this._config.edit((scope ref conf) | ||
{ | ||
const dir = getcwd(); | ||
|
||
if(!conf.projectDirs.canFind(dir)) | ||
conf.projectDirs ~= dir; | ||
}); | ||
return 0; | ||
} | ||
} | ||
|
||
@Command("daemon register systemd", "Creates a systemd service that runs AimCLITool in Daemon mode.") | ||
final class AimDaemonRegisterSystemd : BaseCommand | ||
{ | ||
private static immutable SYSTEMD_TEMPLATE = import("deploy/systemd.service"); | ||
private static immutable SERVICE_PATH = "/lib/systemd/system/aimd.service"; | ||
|
||
override int onExecute() | ||
{ | ||
import std.file : thisExePath, write; | ||
import aim.common.templater : Templater; | ||
|
||
write(SERVICE_PATH, Templater.resolveTemplate(["$AIM_PATH": thisExePath], SYSTEMD_TEMPLATE)); | ||
Shell.executeEnforceStatusZero("systemctl start aimd"); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module aim.daemon.daemon; | ||
|
||
private | ||
{ | ||
import jaster.cli; | ||
import aim.common, aim.deploy, aim.secrets, aim.daemon; | ||
} | ||
|
||
final class AimDaemon | ||
{ | ||
private IAimCliConfig!AimDaemonConfig _daemonConfig; | ||
|
||
this(IAimCliConfig!AimDaemonConfig daemonConfig) | ||
{ | ||
this._daemonConfig = daemonConfig; | ||
} | ||
|
||
void runForeverLoop() | ||
{ | ||
import core.thread : Thread; | ||
import core.time : seconds; | ||
|
||
Shell.useVerboseOutput = true; | ||
while(true) | ||
{ | ||
tick(); | ||
Thread.sleep(60.seconds); | ||
this._daemonConfig.reload(); | ||
} | ||
} | ||
|
||
private void tick() | ||
{ | ||
import std.file : exists, chdir; | ||
|
||
foreach(dir; this._daemonConfig.value.projectDirs) | ||
{ | ||
if(!exists(dir)) | ||
continue; | ||
|
||
chdir(dir); | ||
Shell.execute("aim deploy trigger check -v"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module aim.daemon.data; | ||
|
||
private | ||
{ | ||
import jaster.cli; | ||
import aim.common, aim.deploy, aim.secrets, aim.daemon; | ||
} | ||
|
||
struct AimDaemonConfig | ||
{ | ||
string[] projectDirs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module aim.daemon; | ||
|
||
public import aim.daemon.commands, aim.daemon.daemon, aim.daemon.data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
$PLACEHOLDERS | ||
$AIM_PATH | ||
$END | ||
$FINISH_CONFIG | ||
[Unit] | ||
Description=Runs AimCLITool in Daemon mode. | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=$AIM_PATH | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target |