diff --git a/janitor.js b/janitor.js index f82a1f83a..670e535ec 100755 --- a/janitor.js +++ b/janitor.js @@ -11,8 +11,6 @@ var assert = require('assert'), authcodedb = require('./src/authcodedb.js'), database = require('./src/database.js'); -var TOKEN_CLEANUP_INTERVAL = 30000; - function initialize(callback) { assert.strictEqual(typeof callback, 'function'); @@ -52,7 +50,7 @@ function run() { cleanupExpiredAuthCodes(function (error) { if (error) console.error(error); - setTimeout(run, TOKEN_CLEANUP_INTERVAL); + process.exit(0); }); }); } diff --git a/setup/container/systemd/cloudron.target b/setup/container/systemd/cloudron.target index c1d70d288..64fc7225f 100644 --- a/setup/container/systemd/cloudron.target +++ b/setup/container/systemd/cloudron.target @@ -2,8 +2,8 @@ Description=Cloudron Smart Cloud Documentation=https://cloudron.io/documentation.html StopWhenUnneeded=true -Requires=apphealthtask.service box.service janitor.service oauthproxy.service -After=apphealthtask.service box.service janitor.service oauthproxy.service +Requires=apphealthtask.service box.service janitor.timer oauthproxy.service +After=apphealthtask.service box.service janitor.timer oauthproxy.service # AllowIsolate=yes [Install] diff --git a/setup/container/systemd/janitor.service b/setup/container/systemd/janitor.service index 7e905bdf6..3f7811740 100644 --- a/setup/container/systemd/janitor.service +++ b/setup/container/systemd/janitor.service @@ -1,16 +1,15 @@ [Unit] Description=Cloudron Janitor OnFailure=crashnotifier@%n.service -StopWhenUnneeded=true [Service] -Type=idle +Type=simple WorkingDirectory=/home/yellowtent/box -Restart=always -ExecStart=/usr/bin/node --optimize_for_size --max_semi_space_size=5 --max_old_space_size=30 /home/yellowtent/box/janitor.js +Restart=no +ExecStart=/usr/bin/node /home/yellowtent/box/janitor.js Environment="HOME=/home/yellowtent" "USER=yellowtent" "DEBUG=box*,connect-lastmile" "BOX_ENV=cloudron" "NODE_ENV=production" KillMode=process User=yellowtent Group=yellowtent MemoryLimit=50M - +WatchdogSec=30 diff --git a/setup/container/systemd/janitor.timer b/setup/container/systemd/janitor.timer new file mode 100644 index 000000000..cda634646 --- /dev/null +++ b/setup/container/systemd/janitor.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Cloudron Janitor +StopWhenUnneeded=true + +[Timer] +# this activates it immediately +OnBootSec=0 +OnUnitActiveSec=30min +Unit=janitor.service +