Hi Ayman,
Ok, I'll reply here and you can link this post to the other one afterwards. Bear in mind that I'm assuming a few things:
- You want to use different config files
- You want to run all the instances of Circuits as the same user
- Each Circuits instance will use a different log file and in the same directory (actually, this must be this way or you will corrupt the log file)
Based of those conditions, the following systemd unit file should do the job:
[Unit]
Description=Start Circuits component in its own Python Virtual Environment
After=network-online.target
[Service]
Environment="APP_LOCK_FILE=~/.resilient/%I"
User=integration
ExecStart=/path/to/python /path/to/resilient_circuits/run.py --logfile /path/to/your/logs/directory/%I.log --config-file /path/to/your/configuration directory/%I/app.config
ExecStop=/bin/kill -p $MAINPID
[Install]
WantedBy=multi-user.target
Notice that you don't actually need different Python virtual environments unless you want to have different components and/or Python dependencies installed in each of them. If that's the case, you can simply used the path to the Python binary in the virtual environment instead of the default one. More importantly, this unit allows you to run N instances, which you can do in this way:
systemctl start circuits@my_first_org
Basically, whatever you type after the '@' will we pass to the unit in the %I variable. Using this trick you can tweak your unit definition to make it as reusable as needed.
I hope this helps. If you have any problem, just let me know :)
------------------------------
Regards,
Carlos Ortigoza
------------------------------
Original Message:
Sent: Tue March 10, 2020 04:29 AM
From: Ayman Sabri
Subject: Running multiple resilient circuits in multiple virtualenv for MSSPs
Hi Carlos,
Any updates on how to resolve this :( ?
Thank you
------------------------------
Ayman Sabri Cyber Security Analyst II
Original Message:
Sent: Mon March 09, 2020 05:22 AM
From: Ayman Sabri
Subject: Running multiple resilient circuits in multiple virtualenv for MSSPs
Hi Carlos,
In the other post, Williams asked me to create a new post for my request:
https://community.ibm.com/community/user/security/communities/community-home/digestviewer/viewthread?GroupId=2845&MessageKey=251b90f8-1dcd-408a-90d6-856b18bce452&CommunityKey=d2f71e8c-108e-4652-b59c-29d61af7163e&tab=digestviewer&ReturnUrl=%2fcommunity%2fuser%2fsecurity%2fcommunities%2fcommunity-home%2fdigestviewer%3fcommunitykey%3dd2f71e8c-108e-4652-b59c-29d61af7163e%26tab%3ddigestviewer
looking forward to see the solution.
PS: should i create in integration user for each virtual env to run resilient circuits ?
Thank you soo much
------------------------------
Ayman Sabri Cyber Security Analyst II
Original Message:
Sent: Mon March 09, 2020 05:15 AM
From: Carlos Ortigoza
Subject: Running multiple resilient circuits in multiple virtualenv for MSSPs
Hi Ayman,
Assuming that you are not using any keyring to store your secrets and that requires manual interaction, using a systemd unit is a good approach. However, I think you have a few issues with your unit definition:
- You cannot refer to the home path of the user in ExecStart. Although this is a full path, Systemd forces you to start the path with '/'. In your case I think it would be something like '/home/integration/.../python'
- You should not run the unit as root. For this, you can add "User=integration"
- If you are planning to use this unit like this for multiple Circuits instances running in parallel, then it won't work. They all will try to use the same lock file and therefore they will refuse to start.
Regarding the last point, having 28 different Systemd units for all your child organizations is inconvenient but there are nice systemd tricks you can use to use the same unit and I can give you an basic example of how to do this. Can you share the link to the other post you mentioned? I would post the answer there so more people can make use of it if they need it.
------------------------------
Regards,
Carlos Ortigoza
Original Message:
Sent: Mon March 09, 2020 05:00 AM
From: Ayman Sabri
Subject: Running multiple resilient circuits in multiple virtualenv for MSSPs
Hello,
I'm using resilient for MSSPs with more than 28 child organization, and i created a virtual environment for each child.
I installed resilient circuits for each virtual environment and run circuits by created a run.py .
~/my_virtual_env/lib/python2.7/site-packages/resilient_circuits/run.py
#!/usr/bin/env python
from resilient_circuits import app
import os
os.environ["APP_CONFIG_FILE"] = "childorg.app.config"
os.environ["APP_LOCK_FILE"] = "childorg.lock.file"
os.environ["APP_LOG_DIR"] = "childorg.app.log"
app.run()
My request, is how can keep the resilient circuits running in each virtual environment ?
I asked in an other threat about the ability to use this config :
[Unit]
Description=Resilient-Circuits Service
After=resilient.service
Requires=resilient.service
[Service]
Type=simple
ExecStart=~/my-virtual_env/bin/python ~/my_virtual_env/lib/python2.7/site-packages/resilient_circuits/
Restart=always
TimeoutSec=10
Environment=APP_CONFIG_FILE=~/my_virtual_env/lib/python2.7/site-packages/resilient_circuits/childorg.app.config
Environment=APP_LOCK_FILE=/home/integration/.resilient/childorg.lock.file
[Install]
WantedBy=multi-user.target
Can you help me resolving this or there is another way to do this ? thanks in advance.
------------------------------
Ayman Sabri Cyber Security Analyst II
------------------------------