Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the recommended was to start opencanary when the system starts ? #73

Closed
ajhubs opened this issue Aug 6, 2019 · 31 comments
Closed

Comments

@ajhubs
Copy link

ajhubs commented Aug 6, 2019

I have tried starting the canary at boot via crontab and also by creating a service, I get the emails stating the deamons have all started and the canary is running, but some don’t work I.e. ssh smb. etc, but they do work if I start opencanary manually ?

What is the recommended way to start the canary at boot ?

Thanks

@HybridAU
Copy link
Contributor

HybridAU commented Aug 6, 2019

I did a blog post ages ago where I'd installed OpenCanary on a RaspberryPi. It's a little bit outdated now and I should update it, but it should still work. I created a systemd service which I saved into /etc/systemd/system/opencanary.service

[Unit]
Description=OpenCanary honeypot
After=syslog.target
After=network.target

[Service]
User=pi
Restart=always
Environment=VIRTUAL_ENV=/home/pi/canary-env/
Environment=PATH=$VIRTUAL_ENV/bin:/usr/bin:$PATH
WorkingDirectory=/home/pi/canary-env/bin
ExecStart=/home/pi/canary-env/bin/opencanaryd --dev

[Install]
WantedBy=multi-user.target

You will obviously need to update the paths to wherever you have installed OpenCanary and then start it with sudo systemctl enable opencanary.service

The other thing that occurs to me is that you mention ssh and smb. You need root access to start those services (because they use low port numbers) so I'd check whatever way you are starting it, the user it runs as has root access.

@ajhubs
Copy link
Author

ajhubs commented Aug 6, 2019

Thank you :)
Your service is much more sophisticated than mine, unfortunate it seems to have the same issue as mine, ftp works, http works, telnet works, but when I access my smb share it does nothing, even though it says the service has started ? - i even tried running the service as root as a test.

Any thoughts on why - I have tried smbd with and without requiring a pw and it makes no difference ?

Thanks again for your reply

@ajhubs
Copy link
Author

ajhubs commented Aug 10, 2019

Hi think I’ve solved this, the python invitoment must be placed in the root user home directory, and the service run as root, once set up as below
All canary functions start with the OS and work perfectly :)

(opencanary.service)

[Unit]
Description=OpenCanary honeypot
After=syslog.target
After=network.target

[Service]
User=root
Restart=always
Environment=VIRTUAL_ENV=/root/env/
Environment=PATH=$VIRTUAL_ENV/bin:/usr/bin:$PATH
WorkingDirectory=/root/env/bin
ExecStart=/root/env/bin/opencanaryd --dev

[Install]
WantedBy=multi-user.target

@jayjb
Copy link
Contributor

jayjb commented Sep 4, 2019

Hey @ajhubs,

Thanks so much for this contribution. I am sure many people will be looking for something like this. Ill mark it down to be added to the wiki for folks to find easily.

@sevenlayersinc
Copy link

I'm running mine out of /opt/canaries

When I start it manually, it works as it should. When I try to add a service, it either starts then immediately shuts down or it repeatedly starts and stops. Any ideas of how to track down what is causing the SIGTERM?

(opencanary.service)

[Unit]
Description=OpenCanary
After=syslog.target
After=network.target

[Service]
User=root
Restart=always
Environment=VIRTUAL_ENV=/opt/canaries/env/
Environment=PATH=$VIRTUAL_ENV/bin:/usr/bin:$PATH
WorkingDirectory=/opt/canaries/env/bin
ExecStart=/opt/canaries/env/bin/opencanaryd --start

[Install]
WantedBy=multi-user.target

(syslog)

Sep 18 03:17:15 canary opencanaryd: [-] Loading /opt/canaries/env/bin/opencanary.tac...
Sep 18 03:17:15 canary opencanaryd: [-] Loaded.
Sep 18 03:17:15 canary opencanaryd: [-] twistd 18.4.0 (/opt/canaries/env/bin/python2 2.7.15) starting up.
Sep 18 03:17:15 canary opencanaryd: [-] reactor class: twisted.internet.epollreactor.EPollReactor.
Sep 18 03:17:15 canary opencanaryd: [-] FTPFactory starting on 21
Sep 18 03:17:15 canary opencanaryd: [-] Starting factory <twisted.protocols.ftp.FTPFactory instance at 0x7f8aa31adcf8>
Sep 18 03:17:15 canary opencanaryd: [-] Received SIGTERM, shutting down.
Sep 18 03:17:15 canary opencanaryd: [-] (TCP Port 21 Closed)
Sep 18 03:17:15 canary opencanaryd: [-] Stopping factory <twisted.protocols.ftp.FTPFactory instance at 0x7f8aa31adcf8>
Sep 18 03:17:15 canary opencanaryd: [-] Main loop terminated.
Sep 18 03:17:15 canary opencanaryd: [-] Server Shut Down.
Sep 18 03:17:15 canary systemd[1]: opencanary.service: Service hold-off time over, scheduling restart.
Sep 18 03:17:15 canary systemd[1]: opencanary.service: Scheduled restart job, restart counter is at 1.
Sep 18 03:17:15 canary systemd[1]: Stopped OpenCanary.

@corysolovewicz
Copy link

Awesome, thanks for the writeup. @HybridAU I was wondering how to do this same thing and came across this thread which helped out.

@ivnmad
Copy link

ivnmad commented Feb 16, 2020

@sevenlayersinc I'm having the same issue.
Did you ever manage to find a solution?

@loganmarchione
Copy link

@sevenlayersinc - I'm having the same issue (I also saw your blog post). I was able to get mine to run using --dev instead of --start. Not sure what the difference is in the those flags (opencanaryd is a bash script that takes those flags and then passes other flags to other programs).

@Houdini7
Copy link

@loganmarchione try resetting the 'monitored' protocols back to FTP only. (that's the default when you initially install OpenCanary)
I had the same experience because I had turned on too much and it was colliding with itself (poorly configured by me)

@loganmarchione
Copy link

@Houdini7 Unfortunately this was on a new install with a new config file

@jayjb
Copy link
Contributor

jayjb commented Aug 24, 2020

Hey folks,

I'll take a look at this this week and let you know.

Sorry for the delay

@jayjb
Copy link
Contributor

jayjb commented Aug 31, 2020

Hey folks,

So i got the following systemd file to work; let me know if it works for you.

[Unit]
Description=OpenCanary
After=syslog.target
After=network.target

[Service]
User=root
Type=oneshot
RemainAfterExit=yes
ExecStart=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --start
ExecStop=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

where /root/ubuntuvb-home/opencanary/opencanaryenv3 is the virtual environment that i installed my Opencanary into.

@ivnmad
Copy link

ivnmad commented Aug 31, 2020

It seems to work.. It started the service and it doesn't loop.
This is the outcome when checking the services status:

sudo systemctl status opencanary.service

● opencanary.service - OpenCanary HoneyPot
Loaded: loaded (/etc/systemd/system/opencanary.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Mon 2020-08-31 20:07:37 BST; 29s ago
Process: 450 ExecStart=/home/pi/canary-env/bin/opencanaryd --start (code=exited, status=0/SUCCESS)
Main PID: 450 (code=exited, status=0/SUCCESS)

Aug 31 20:07:37 #### opencanaryd[696]: [-] Stopping factory <opencanary.modules.ssh.HoneyPotSSHFactory instance
Aug 31 20:07:37 #### opencanaryd[696]: [-] (TCP Port 21 Closed)
Aug 31 20:07:37 #### opencanaryd[696]: [-] Stopping factory <twisted.protocols.ftp.FTPFactory instance at 0x74b
Aug 31 20:07:37 #### opencanaryd[696]: [-] (TCP Port 80 Closed)
Aug 31 20:07:37 #### opencanaryd[696]: [-] Stopping factory <twisted.web.server.Site instance at 0x74b49328>
Aug 31 20:07:37 #### opencanaryd[696]: [-] (TCP Port 23 Closed)
Aug 31 20:07:37 #### opencanaryd[696]: [-] Stopping factory <twisted.internet.protocol.ServerFactory instance a
Aug 31 20:07:37 #### opencanaryd[696]: [-] Main loop terminated.
Aug 31 20:07:37 #### opencanaryd[696]: [-] Server Shut Down.
Aug 31 20:07:37 #### systemd[1]: opencanary.service: Succeeded.

@loganmarchione
Copy link

@jayjb - Also working for me, thanks! It successfully starts, stops, and works on reboot. Can this be added to the documentation and/or README?

@OzGav
Copy link
Contributor

OzGav commented Sep 9, 2020

Hmmm... I went a simple option on Ubuntu 18.04 and I use a small script called start_canary.sh

#!/bin/bash
. canary-env/bin/activate
opencanaryd --start

and then I ran crontab -e and added @reboot /root/start_canary.sh

Seems to work ok?

@loganmarchione
Copy link

@OzGav the only issue there is if the service dies, you can't restart it. I believe you can tell systemd to start a crashed service with Restart=always.

@OzGav
Copy link
Contributor

OzGav commented Sep 16, 2020

@OzGav if the service dies, you can't restart it..

OK I assume you mean automatically; watchdog style?

@cyberflamingo
Copy link

Let me chime in to add my experience, which is similar to @loganmarchione 's one.

[Unit]
Description=OpenCanary
After=syslog.target network.target

[Service]
User=root
Restart=always
RemainAfterExit=yes
ExecStart=/root/env/bin/opencanaryd --start
ExecStop=/root/env/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

I'm no systemd expert but if I understood the doc correctly Type=oneshot is useful for one time script execution, not daemon loading like we are trying to achieve here, which is why I get rid of it.

Another gotcha to be aware of for some service is name resolution error:

Sep 26 12:48:52 NotAHoneyPot opencanaryd[448]: requests.exceptions.ConnectionError: HTTPSConnectionPool(host='hooks.slack.com', port=443): Max retries exceeded with url: /services/foo/bar/foobar (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xffffa9661dd8>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
Sep 26 12:48:52 NotAHoneyPot opencanaryd[448]: Failed to load application: HTTPSConnectionPool(host='hooks.slack.com', port=443): Max retries exceeded with url: /services/foo/bar/foobar (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xffffa9661dd8>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

Here I believe the daemon tries to resolve webhook's URL for Slack before name resolution kicks in. This problem should be alleviated by Restart=always but some people may see better results in combination with network-online.target in-lieu of network.target (the former waits for DNS to wake up as well).

Tuning the wait time between each retry and the number of retry are other solutions.

@emperortomato
Copy link

I'm having trouble getting opencanary to start properly at boot on Ubuntu 20.04. I've spent quite a while trying to figure this out, but this is a really weird problem.

My systemd service file looks like this. My virtualenv is /usr/local/bin/opencanary.

[Unit]
Description=OpenCanary
After=network.target

[Service]
Type=simple
PIDFile=/usr/local/bin/opencanary/bin/opencanaryd.pid
ExecStart=/usr/local/bin/opencanary/bin/opencanaryd --dev
ExecStop=/usr/local/bin/opencanary/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

The really screwy thing is that the service starts, but doesn't complete its startup until a user logs in on the console. Logging in remotely via SSH doesn't cause the service startup to proceed, but logging in locally on the console causes the service to finish initializing. It doesn't seem to matter which user logs in, be it root or an unprivileged user.

For example, post-reboot, before logging in on console, checking service state over SSH -- it claims to be started here, and there are opencanary processes running, but they aren't actually listening on any service ports; I currently only have mysql enabled for testing purposes.

root@server:~# systemctl status opencanary
● opencanary.service - OpenCanary
     Loaded: loaded (/etc/systemd/system/opencanary.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2020-12-25 12:14:33 CST; 22s ago
   Main PID: 605 (opencanaryd)
      Tasks: 3 (limit: 2278)
     Memory: 53.2M
     CGroup: /system.slice/opencanary.service
             ├─605 /bin/bash /usr/local/bin/opencanary/bin/opencanaryd --dev
             ├─612 sudo /usr/local/bin/opencanary/bin/twistd -noy /usr/local/bin/opencanary/bin/opencanary.tac
             └─619 /usr/local/bin/opencanary/bin/python /usr/local/bin/opencanary/bin/twistd -noy /usr/local/bin/opencanary/bin/opencanary.tac

Dec 25 12:14:33 server systemd[1]: Started OpenCanary.
Dec 25 12:14:33 server sudo[612]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/local/bin/opencanary/bin/twistd -noy /usr/local/bin/opencanary/bin/opencanary.tac
Dec 25 12:14:33 server sudo[612]: pam_unix(sudo:session): session opened for user root by (uid=0)

Post-reboot, after logging in on console:

root@server:~# systemctl status opencanary
● opencanary.service - OpenCanary
     Loaded: loaded (/etc/systemd/system/opencanary.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2020-12-25 12:14:33 CST; 2min 11s ago
   Main PID: 605 (opencanaryd)
      Tasks: 3 (limit: 2278)
     Memory: 59.2M
     CGroup: /system.slice/opencanary.service
             ├─605 /bin/bash /usr/local/bin/opencanary/bin/opencanaryd --dev
             ├─612 sudo /usr/local/bin/opencanary/bin/twistd -noy /usr/local/bin/opencanary/bin/opencanary.tac
             └─619 /usr/local/bin/opencanary/bin/python /usr/local/bin/opencanary/bin/twistd -noy /usr/local/bin/opencanary/bin/opencanary.tac

Dec 25 12:16:15 server opencanaryd[619]: Can't import RDP. Please ensure you have RDP installed.
Dec 25 12:16:15 server opencanaryd[619]: Can't import SNMP. Please ensure you have Scapy installed.
Dec 25 12:16:15 server opencanaryd[619]: {"dst_host": "", "dst_port": -1, "local_time": "2020-12-25 18:16:15.478413", "logdata": {"msg": {"logdata": "Added service from class C>
Dec 25 12:16:15 server opencanaryd[619]: {"dst_host": "", "dst_port": -1, "local_time": "2020-12-25 18:16:15.480493", "logdata": {"msg": "Canary running!!!"}, "logtype": 1001, >
Dec 25 12:16:15 server opencanaryd[619]: 2020-12-25T12:14:35-0600 [-] Loading /usr/local/bin/opencanary/bin/opencanary.tac...
Dec 25 12:16:15 server opencanaryd[619]: 2020-12-25T12:16:15-0600 [-] Loaded.
Dec 25 12:16:15 server opencanaryd[619]: 2020-12-25T12:16:15-0600 [twisted.scripts._twistd_unix.UnixAppLogger#info] twistd 19.10.0 (/usr/local/bin/opencanary/bin/python 3.8.5) >
Dec 25 12:16:15 server opencanaryd[619]: 2020-12-25T12:16:15-0600 [twisted.scripts._twistd_unix.UnixAppLogger#info] reactor class: twisted.internet.epollreactor.EPollReactor.
Dec 25 12:16:15 server opencanaryd[619]: 2020-12-25T12:16:15-0600 [-] SQLFactory starting on 3306
Dec 25 12:16:15 server opencanaryd[619]: 2020-12-25T12:16:15-0600 [opencanary.modules.mysql.SQLFactory#info] Starting factory <opencanary.modules.mysql.SQLFactory object at 0x7>

Note the application-level timestamps of these two lines, in particular:

Dec 25 12:16:15 server opencanaryd[619]: 2020-12-25T12:14:35-0600 [-] Loading /usr/local/bin/opencanary/bin/opencanary.tac...
Dec 25 12:16:15 server opencanaryd[619]: 2020-12-25T12:16:15-0600 [-] Loaded.

It gets to the point of "Loading /usr/local/bin/opencanary/bin/opencanary.tac...", and does not proceed further until a user logs in on the console, which I did almost 2 minutes later, at which point the service completes its startup. I've never seen anything like this.

Does anyone have any ideas about what might be going on, here? I've tried loading the service with an @reboot cron job, and get the same exact results.

@emperortomato
Copy link

Um, as a follow-up to my previous post, I think I found a completely nonsensical workaround. I don't understand why this seems to work.

I changed my service ExecStart to use --start rather than --dev (I thought having the output in systemctl might be useful for debugging, but it wasn't helping), and set Type=forking since opencanaryd exits after starting twistd.

[Unit]
Description=OpenCanary
After=network.target

[Service]
Type=forking
PIDFile=/usr/local/bin/opencanary/bin/opencanaryd.pid
ExecStart=/usr/local/bin/opencanary/bin/opencanaryd --start
ExecStop=/usr/local/bin/opencanary/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

This doesn't make any sense, but enabling --spew logging for twistd seems to get it to start up quickly without intervention. I modified the opencanaryd start block, removing the --syslog and --prefix params, and adding --spew and --logfile params:

if [ "${cmd}" == "--start" ]; then
    if [ ! -f ~/.opencanary.conf -a ! -f opencanary.conf -a ! -f /etc/opencanaryd/opencanary.conf ]; then
        echo "[e] No config file found, please create one with \"opencanaryd --copyconfig\""
        exit 1
    fi

    sudo "${DIR}/twistd" -y "${DIR}/opencanary.tac" --pidfile="${PIDFILE}" --spew --logfile=/var/log/opencanary/twistd.log

The log messages end up going to syslog and the log file, so the logfile param is probably not needed. You could probably leave the --syslog and --prefix params as-is and just add --spew. I have no idea why this seems to work; I only enabled it in the first place so that I could try debugging where it was getting hung up. spew dumps a ton of output into syslog/the log file, so it's not great, but after multiple reboots it seems to be getting the service to start quickly, for whatever reason...

This seems to suggest maybe there's something going wrong w/ Twisted? I have v19.10.0 installed.

@jvedman
Copy link

jvedman commented Feb 1, 2021

Thank you, emperortomato. This worked for me, the service starts up quickly and is pretty nimble with stops and starts, but I am a little concerned about how quickly the log file created for twistd is filling up and rolling over. I've been running for less than an hour and already have 4 1M rolled-over log files. Are you seeing this as well?
There is a particular block of stuff that keeps repeating as follows:

2021-02-01T15:48:18-0500 [stdout#info] method callLater of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:18-0500 [stdout#info] method __init__ of twisted.internet.base.DelayedCall at 139881927555664
2021-02-01T15:48:18-0500 [stdout#info] method timeout of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:18-0500 [stdout#info] method _insertNewDelayedCalls of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:18-0500 [stdout#info] method activate_delay of twisted.internet.base.DelayedCall at 139881927555664
2021-02-01T15:48:18-0500 [stdout#info] method doPoll of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:19-0500 [stdout#info] method runUntilCurrent of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:19-0500 [stdout#info] method _insertNewDelayedCalls of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:19-0500 [stdout#info] method _updateLogDateTime of twisted.web.server.Site at 139881925072528
2021-02-01T15:48:19-0500 [stdout#info] function datetimeToLogString in /env/local/lib/python2.7/site-packages/twisted/web/http.py, line 238
2021-02-01T15:48:19-0500 [stdout#info] method callLater of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:19-0500 [stdout#info] method __init__ of twisted.internet.base.DelayedCall at 139881918747504
2021-02-01T15:48:19-0500 [stdout#info] method timeout of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:19-0500 [stdout#info] method _insertNewDelayedCalls of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:19-0500 [stdout#info] method activate_delay of twisted.internet.base.DelayedCall at 139881918747504
2021-02-01T15:48:19-0500 [stdout#info] method doPoll of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:20-0500 [stdout#info] method runUntilCurrent of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:20-0500 [stdout#info] method _insertNewDelayedCalls of twisted.internet.epollreactor.EPollReactor at 139881921433488
2021-02-01T15:48:20-0500 [stdout#info] method _updateLogDateTime of twisted.web.server.Site at 139881925072528
2021-02-01T15:48:20-0500 [stdout#info] function datetimeToLogString in /env/local/lib/python2.7/site-packages/twisted/web/http.py, line 238

@emperortomato
Copy link

Hmm, I only seem to be seeing massive log spew on startup; after that it's pretty quiet.

@jvedman
Copy link

jvedman commented Feb 1, 2021

Okay, I'll check again after it's been running to see if it is still hyperactive. The good news is that it doesn't seem to be particularly valuable info, so I can run a cron job to periodically delete the files if needed.

@jvedman
Copy link

jvedman commented Feb 2, 2021

I've done exactly the same setup on 4 vms, and seeing the same thing across all of them. My setup is Ubuntu server 18.04.5 LTS fully patched, so python 2.7 and twistd 20.3.0. I'm going to build a server 20.0.4 vm today to test as well.

@jayjb
Copy link
Contributor

jayjb commented Feb 2, 2021

Hi @jvedman,

I suspect you seeing all that because you included --spew. Opencanary was its own logging mechanisms built in that you can specify in the configuration file. I've just updated the documentation to getting Opencanary running on the latest Ubuntu. On my list is to also add the best practice for starting it on system boot (which i suspect will be something in line with @emperortomato's systemd service file)

@jayjb
Copy link
Contributor

jayjb commented Feb 2, 2021

Hi @emperortomato,

Um, as a follow-up to my previous post, I think I found a completely nonsensical workaround. I don't understand why this seems to work.

I changed my service ExecStart to use --start rather than --dev (I thought having the output in systemctl might be useful for debugging, but it wasn't helping), and set Type=forking since opencanaryd exits after starting twistd.

[Unit]
Description=OpenCanary
After=network.target

[Service]
Type=forking
PIDFile=/usr/local/bin/opencanary/bin/opencanaryd.pid
ExecStart=/usr/local/bin/opencanary/bin/opencanaryd --start
ExecStop=/usr/local/bin/opencanary/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

This doesn't make any sense, but enabling --spew logging for twistd seems to get it to start up quickly without intervention. I modified the opencanaryd start block, removing the --syslog and --prefix params, and adding --spew and --logfile params:

if [ "${cmd}" == "--start" ]; then
    if [ ! -f ~/.opencanary.conf -a ! -f opencanary.conf -a ! -f /etc/opencanaryd/opencanary.conf ]; then
        echo "[e] No config file found, please create one with \"opencanaryd --copyconfig\""
        exit 1
    fi

    sudo "${DIR}/twistd" -y "${DIR}/opencanary.tac" --pidfile="${PIDFILE}" --spew --logfile=/var/log/opencanary/twistd.log

The log messages end up going to syslog and the log file, so the logfile param is probably not needed. You could probably leave the --syslog and --prefix params as-is and just add --spew. I have no idea why this seems to work; I only enabled it in the first place so that I could try debugging where it was getting hung up. spew dumps a ton of output into syslog/the log file, so it's not great, but after multiple reboots it seems to be getting the service to start quickly, for whatever reason...

This seems to suggest maybe there's something going wrong w/ Twisted? I have v19.10.0 installed.

Instead of the Type=forking to Type=oneshot. Did you try this service file:

[Unit]
Description=OpenCanary
After=syslog.target
After=network.target

[Service]
User=root
Type=oneshot
RemainAfterExit=yes
ExecStart=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --start
ExecStop=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

@Taomyn
Copy link

Taomyn commented Jul 10, 2021

This tested working for me on my RPi-4, thanks

Instead of the Type=forking to Type=oneshot. Did you try this service file:

[Unit]
Description=OpenCanary
After=syslog.target
After=network.target

[Service]
User=root
Type=oneshot
RemainAfterExit=yes
ExecStart=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --start
ExecStop=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

@jayjb
Copy link
Contributor

jayjb commented Aug 26, 2021

Closing this thread a solution that has worked. It may need changes on different OSes (or tweaks):

[Unit]
Description=OpenCanary
After=syslog.target
After=network-online.target

[Service]
User=root
Type=oneshot
RemainAfterExit=yes
Restart=always
ExecStart=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --start
ExecStop=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

Please note that /root/ubuntuvb-home/opencanary/opencanaryenv3 is the full path to the virtual environment that has your Opencanary installed.

@chimbuzi
Copy link

Closing this thread a solution that has worked. It may need changes on different OSes (or tweaks):

[Unit]
Description=OpenCanary
After=syslog.target
After=network-online.target

[Service]
User=root
Type=oneshot
RemainAfterExit=yes
Restart=always
ExecStart=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --start
ExecStop=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

Please note that /root/ubuntuvb-home/opencanary/opencanaryenv3 is the full path to the virtual environment that has your Opencanary installed.

This doesn't seem to work on Debian 11. Indeed, I'm not sure how it ever worked properly - if systemd is parsing the unit file properly then Type=oneshot should be mutually exclusive of Restart=always.

In this case, we only want to pass a single ExecStart=..., so should be using Type=simple instead. Can confirm that this works on Debian 11.

@Taomyn
Copy link

Taomyn commented Oct 20, 2021

Closing this thread a solution that has worked. It may need changes on different OSes (or tweaks):

[Unit]
Description=OpenCanary
After=syslog.target
After=network-online.target

[Service]
User=root
Type=oneshot
RemainAfterExit=yes
Restart=always
ExecStart=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --start
ExecStop=/root/ubuntuvb-home/opencanary/opencanaryenv3/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

Please note that /root/ubuntuvb-home/opencanary/opencanaryenv3 is the full path to the virtual environment that has your Opencanary installed.

This doesn't seem to work on Debian 11. Indeed, I'm not sure how it ever worked properly - if systemd is parsing the unit file properly then Type=oneshot should be mutually exclusive of Restart=always.

In this case, we only want to pass a single ExecStart=..., so should be using Type=simple instead. Can confirm that this works on Debian 11.

Also works with Fedora 34

@GunnarHelliesen
Copy link

FYI, on Ubuntu 22, Type=oneshot did not work for me. It caused systemctl start to hang. I had to use:

Type=simple

And then everything worked as expected. I.e.:

[Unit]
Description=OpenCanary
After=syslog.target
After=network-online.target

[Service]
User=root
Type=simple
RemainAfterExit=yes
Restart=always
PIDFile=<PATH>/bin/opencanaryd.pid
ExecStart=<PATH>/bin/opencanaryd --start
ExecStop=<PATH>/bin/opencanaryd --stop

[Install]
WantedBy=multi-user.target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests