Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- root@moo# cat run_nginx.sh
- #!/bin/bash
- ME=$(basename $0 | sed 's/\.sh//' | sed 's/run\_//')
- ID=`docker run \
- --net=host \
- -v /data/stuff/conf/nginx/sites-available:/etc/nginx/sites-enabled \
- -v /data/stuff/conf/nginx/nginx.conf:/etc/nginx/nginx.conf \
- -v /data/stuff:/data \
- -d \
- 192.168.1.1:5000/jessie-stack:latest \
- /usr/local/openresty/nginx/sbin/nginx \
- -c /etc/nginx/nginx.conf`
- trap "echo Stopping $ID; docker stop $ID; /root/ops/services/scripts/systemd-log-stop.pl $ME" SIGINT
- echo "[supervisor - shell] Executed PID: $$"
- /root/ops/services/scripts/systemd-log.pl $ME $ID
- docker logs -f $ID
- root@moo:~/# cat /etc/supervisor/conf.d/nginx.conf
- [program:nginx]
- command=/root/ops/services/scripts/run_nginx.sh
- user=root
- redirect_stderr=true
- autostart=true
- autorestart=true
- stopsignal=INT
- stopasgroup=true
- root@moo:~/# cat systemd-log-stop.pl
- #!/usr/bin/perl
- $service = $ARGV[0];
- if($service eq "") { exit };
- &main;
- sub main {
- $initsys = `ps aux | grep systemd | grep -v grep | wc -l`;
- if($initsys >= 5) {
- $ret = `systemctl stop $service-log`;
- print $ret;
- }
- }
- root@moo:~/ops/services/scripts# cat systemd-log.pl
- #!/usr/bin/perl
- $service = $ARGV[0];
- $id = $ARGV[1];
- if($service eq "" || $id eq "") { exit };
- &main;
- sub main {
- $initsys = `ps aux | grep systemd | grep -v grep | wc -l`;
- if($initsys >= 5) {
- $service = $service."-log";
- &create_service;
- }
- }
- sub create_service {
- open(FILE, ">/etc/systemd/system/$service.service");
- print FILE <<EOF;
- [Unit]
- Description=$service
- [Service]
- ExecStart=/usr/bin/docker logs -f $id
- [Install]
- WantedBy=multi-user.target
- EOF
- close(FILE);
- $ret = `systemctl daemon-reload`;
- $ret = `systemctl start $service`;
- }
Advertisement
Add Comment
Please, Sign In to add comment