Cronicle icon indicating copy to clipboard operation
Cronicle copied to clipboard

Systemd service file

Open LordMike opened this issue 6 years ago • 8 comments

Hey,

Does anybody have a systemd service file that can be used to control the Cronicle daemon? The idea is to be able to start, stop, restart on failure etc.

Mike.

LordMike avatar Nov 15 '18 21:11 LordMike

It ships with one:

https://github.com/jhuckaby/Cronicle/blob/master/bin/cronicled.init

Instructions for enabling here:

https://github.com/jhuckaby/Cronicle#server-startup

Server Startup

Here are the instructions for making Cronicle automatically start on server boot (Linux only). Type these commands as root:

cp /opt/cronicle/bin/cronicled.init /etc/init.d/cronicled
chmod 775 /etc/init.d/cronicled

Then, if you have a RedHat-style Linux (i.e. Fedora, CentOS), type this:

chkconfig cronicled on

Or, if you have Debian-style Linux (i.e. Ubuntu), type this:

update-rc.d cronicled defaults

For multi-server clusters, you'll need to repeat these steps on each server.

jhuckaby avatar Nov 15 '18 21:11 jhuckaby

Ah, but systemd replaces SysInitV.

I went ahead and created a systemd service file.

[Install]
WantedBy=multi-user.target

[Service]
Type=forking
PIDFile=/opt/cronicle/logs/cronicled.pid
ExecStart=/opt/cronicle/bin/control.sh start
ExecStop=/opt/cronicle/bin/control.sh stop

Example status output from systemd:

# service cronicle status
● cronicle.service
   Loaded: loaded (/etc/systemd/system/cronicle.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-11-15 22:35:31 CET; 3min 4s ago
 Main PID: 16087 (Cronicle Server)
    Tasks: 10 (limit: 4915)
   CGroup: /system.slice/cronicle.service
           └─16087 Cronicle Server

Nov 15 22:35:29 victoria systemd[1]: Starting cronicle.service...
Nov 15 22:35:29 victoria control.sh[16059]: /opt/cronicle/bin/control.sh start: Starting up Cronicle Daemon...
Nov 15 22:35:30 victoria control.sh[16059]: /opt/cronicle/bin/control.sh start: Cronicle Daemon started
Nov 15 22:35:30 victoria systemd[1]: cronicle.service: Can't open PID file /opt/cronicle/logs/cronicled.pid (yet?) after start: No such file or directory
Nov 15 22:35:31 victoria systemd[1]: Started cronicle.service.

LordMike avatar Nov 15 '18 21:11 LordMike

Ah, thanks. I did not know about that. I'll do some research and update the docs.

jhuckaby avatar Nov 15 '18 21:11 jhuckaby

;)

LordMike avatar Nov 15 '18 21:11 LordMike

https://www.tecmint.com/systemd-replaces-init-in-linux/

https://askubuntu.com/questions/911525/difference-between-systemctl-init-d-and-service

LordMike avatar Nov 15 '18 21:11 LordMike

Also. The docs on systemd services are limited, yet, but here are the two resources I usually pick when looking up stuff:

  • https://wiki.archlinux.org/index.php/systemd
  • https://www.freedesktop.org/software/systemd/man/systemd.service.html

LordMike avatar Nov 15 '18 21:11 LordMike

Much thanks!

jhuckaby avatar Nov 15 '18 21:11 jhuckaby

I recommend to put this in the documentation.

donaldkg avatar Apr 15 '21 03:04 donaldkg

Same, this is crucial information, but not mentioned in the setup instructions.

john8329 avatar Apr 28 '23 14:04 john8329

Hello,

Using @LordMike 's systemd service unit file. When running as a systemd service, I cannot restart the service via the GUI. It just leaves it in a dead state, needing me to use systemctl restart cronicle.service

@jhuckaby When is proper systemd support coming? Its the main init system in a majority of distros...

No pressure :)

Lue.

lue30499 avatar Aug 10 '23 05:08 lue30499

Added in v0.9.27.

https://github.com/jhuckaby/Cronicle/blob/master/docs/CommandLine.md#server-startup

Server Startup

Cronicle will automatically register itself as a system service when it is first installed, so it will automatically start itself on server boot. This is done via the pixl-boot module, and it supports Systemd if available, falling back to Sysv Init or others.

If you do not want Cronicle to automatically start itself on boot, you can disable it with this command:

cd /opt/cronicle
npm run unboot

If you change your mind and want to reenable it, use this command:

cd /opt/cronicle
npm run boot

Important Note: When Cronicle starts on server boot, it typically does not have a proper user environment, namely a PATH environment variable. So if your scripts rely on binary executables in alternate locations, e.g. /usr/local/bin, you may have to restore the PATH and other variables inside your scripts by redeclaring them.

jhuckaby avatar Aug 10 '23 17:08 jhuckaby