mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
switch to auto-restarter daemon
This commit is contained in:
committed by
Keagan McClelland
parent
f68c13f57f
commit
30f8b8e6cd
7
agent/config/restarter.service
Normal file
7
agent/config/restarter.service
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=restarts dead containers
|
||||||
|
Requires=docker.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/bin/bash /root/restarter.sh
|
||||||
18
agent/config/restarter.sh
Normal file
18
agent/config/restarter.sh
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
for CONTAINER in $(docker ps -aq); do
|
||||||
|
EXIT=`docker inspect -f "{{ .State.ExitCode }}" $CONTAINER`
|
||||||
|
if [ $EXIT -eq 0 ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ $EXIT -eq 143 ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [ $EXIT -eq 137 ]; then
|
||||||
|
OOM=`docker inspect -f "{{ .State.OOMKilled }}" $CONTAINER`
|
||||||
|
if [ "$OOM" == "false" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
docker start $CONTAINER
|
||||||
|
done
|
||||||
9
agent/config/restarter.timer
Normal file
9
agent/config/restarter.timer
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=restarter
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnUnitActiveSec=60s
|
||||||
|
OnBootSec=60s
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
@@ -119,6 +119,7 @@ sync_0_2_6 = Synchronizer
|
|||||||
, syncPrepSslIntermediateCaDir
|
, syncPrepSslIntermediateCaDir
|
||||||
, syncPersistLogs
|
, syncPersistLogs
|
||||||
, syncConvertEcdsaCerts
|
, syncConvertEcdsaCerts
|
||||||
|
, syncRestarterService
|
||||||
]
|
]
|
||||||
|
|
||||||
syncCreateAgentTmp :: SyncOp
|
syncCreateAgentTmp :: SyncOp
|
||||||
@@ -536,6 +537,22 @@ replaceDerivativeCerts = do
|
|||||||
liftIO $ renameDirectory sslDirTmp sslDir
|
liftIO $ renameDirectory sslDirTmp sslDir
|
||||||
liftIO $ systemCtl RestartService "nginx" $> ()
|
liftIO $ systemCtl RestartService "nginx" $> ()
|
||||||
|
|
||||||
|
syncRestarterService :: SyncOp
|
||||||
|
syncRestarterService = SyncOp "Install Restarter Service" check migrate False
|
||||||
|
where
|
||||||
|
wantedScript = decodeUtf8 $(embedFile "config/restarter.sh")
|
||||||
|
wantedService = decodeUtf8 $(embedFile "config/restarter.service")
|
||||||
|
wantedTimer = decodeUtf8 $(embedFile "config/restarter.timer")
|
||||||
|
check = do
|
||||||
|
base <- asks $ appFilesystemBase . appSettings
|
||||||
|
liftIO $ not <$> doesPathExist (toS $ "/etc/systemd/system/timers.target.wants/restarter.timer" `relativeTo` base)
|
||||||
|
migrate = do
|
||||||
|
base <- asks $ appFilesystemBase . appSettings
|
||||||
|
liftIO $ writeFile (toS $ "/usr/local/bin/restarter.sh" `relativeTo` base) wantedScript
|
||||||
|
liftIO $ writeFile (toS $ "/etc/systemd/system/restarter.service" `relativeTo` base) wantedService
|
||||||
|
liftIO $ writeFile (toS $ "/etc/systemd/system/restarter.timer" `relativeTo` base) wantedTimer
|
||||||
|
liftIO . run $ systemctl "enable" "restarter.timer"
|
||||||
|
|
||||||
failUpdate :: S9Error -> ExceptT Void (ReaderT AgentCtx IO) ()
|
failUpdate :: S9Error -> ExceptT Void (ReaderT AgentCtx IO) ()
|
||||||
failUpdate e = do
|
failUpdate e = do
|
||||||
ref <- asks appIsUpdateFailed
|
ref <- asks appIsUpdateFailed
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::util::Invoke;
|
||||||
|
|
||||||
const V0_2_7: emver::Version = emver::Version::new(0, 2, 7, 0);
|
const V0_2_7: emver::Version = emver::Version::new(0, 2, 7, 0);
|
||||||
|
|
||||||
@@ -13,6 +14,15 @@ impl VersionT for Version {
|
|||||||
&V0_2_7
|
&V0_2_7
|
||||||
}
|
}
|
||||||
async fn up(&self) -> Result<(), Error> {
|
async fn up(&self) -> Result<(), Error> {
|
||||||
|
for (app_id, _) in crate::apps::list_info().await? {
|
||||||
|
tokio::process::Command::new("docker")
|
||||||
|
.arg("update")
|
||||||
|
.arg("--restart")
|
||||||
|
.arg("no")
|
||||||
|
.arg(app_id)
|
||||||
|
.invoke("Docker")
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn down(&self) -> Result<(), Error> {
|
async fn down(&self) -> Result<(), Error> {
|
||||||
|
|||||||
Reference in New Issue
Block a user