Skip to main content
Topic: Auto-start Cronicle with OpenRC (Troubleshooting) (Read 1190 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Auto-start Cronicle with OpenRC (Troubleshooting)

About 2 weeks ago, I installed Cronicle. From what I recall, Cronicle provided its own service control script. I didn't have to write one myself. While I can start its service manually (via OpenRC), I can't get OpenRC to auto-start the service. I've tried adding it to default and boot runlevels, to no avail. Is there a different runlevel that I should be using for this? Should I use a custom runlevel?

The instructions for install/config are listed on their Github page:
https://github.com/jhuckaby/Cronicle

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #1
Hi, where exactly is the OpenRC service file?

Artix repos do not have cronicle nor its OpenRC service file.

I also could not find any refrence to OpenRC in Cronicles documentation.


Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #2
Is there a different runlevel that I should be using for this?

I would look at the contents of /etc/local.d and read the README.
"Wer alles kann, macht nichts richtig"

Artix USE="runit openrc slim openbox lxde gtk2 qt4 qt5 qt6 conky
-gtk3 -gtk4 -adwaita{cursors,themes,icons} -gnome3 -kde -plasma -wayland "

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #3
Hi, where exactly is the OpenRC service file?

Artix repos do not have cronicle nor its OpenRC service file.

I also could not find any reference to OpenRC in Cronicle's documentation.


I think the service file is listed here in the repo:

The file's contents:
Code: [Select]
#!/bin/sh
#
# init.d script for Cronicle Scheduler
#
# chkconfig: 345 90 10
# description: Cronicle Scheduler

### BEGIN INIT INFO
# Provides:          cronicled
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/Stop Cronicle Scheduler
### END INIT INFO

PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH

/opt/cronicle/bin/control.sh $1

I could be completely wrong though (or it may be incomplete). Strangely enough, I had to put in more effort when looking for a way to support autostart with systemd. Ended up finding that in an issue, where the solution was provided by the person that opened the issue:


The documentation only goes over details for manually starting the service in detail, which makes the task a bit difficult. They appear to have included an init script, but I'm having no luck with getting the service to autostart sadly.

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #4
I would look at the contents of /etc/local.d and read the README.









Should write a .start and .stop file for the service in question and drop them off in the same folder as local.start ? Just making sure I'm interpreting this information correctly.

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #5
Hi, where exactly is the OpenRC service file?

Artix repos do not have cronicle nor its OpenRC service file.

I also could not find any refrence to OpenRC in Cronicles documentation.


Now that I've reviewed the init script, I think it may be missing a few things:
  • Depends: Network, DNS
  • Start function
  • Stop function

Or perhaps it was written for a different init system? Should it look something like this? (incomplete snippet):
Code: [Select]
#!/sbin/openrc-run
#
# OpenRC script for Cronicle Scheduler
#
# chkconfig: 345 90 10
# description: Cronicle Scheduler

### BEGIN INIT INFO
# Provides:          cronicled
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/Stop Cronicle Scheduler
### END INIT INFO


name="Cronicle Daemon"
description="A cron alternative built on Node.js, sporting a web GUI"
command="/opt/cronicle/bin/control.sh"
# command_background="yes"


depend() {
    need localmount net syslog dns
  # need $remote_fs
    provide cronicled
}

start() {
    ebegin "Initialising cronicled..."
    start-stop-daemon --start --exec /opt/cronicle/bin/control.sh start
    eend $?
}

restart() {
    ebegin "Restarting cronicled..."
    start-stop-daemon --start --exec /opt/cronicle/bin/control.sh restart
    eend $?
}

status() {
    ebegin "Retrieving status of cronicled..."
    start-stop-daemon --start --exec /opt/cronicle/bin/control.sh status
    eend $?
}

stop() {
    ebegin "Terminating cronicled..."
    start-stop-daemon --stop --exec /opt/cronicle/bin/control.sh stop
    eend $?
}

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #6
Should write a .start and .stop file for the service in question and drop them off in the same folder as local.start ? Just making sure I'm interpreting this information correctly.

Yes.
"Wer alles kann, macht nichts richtig"

Artix USE="runit openrc slim openbox lxde gtk2 qt4 qt5 qt6 conky
-gtk3 -gtk4 -adwaita{cursors,themes,icons} -gnome3 -kde -plasma -wayland "

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #7
I wrote this OpenRC script draft for it (default runlevel for the time being):

Code: [Select]
#!/sbin/openrc-run
#
# OpenRC script for Cronicle Scheduler
#
# chkconfig: 345 90 10
# description: Cronicle Scheduler

### BEGIN INIT INFO
# Provides:          cronicled
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/Stop Cronicle Scheduler
### END INIT INFO


name="Cronicle Daemon"
description="A cron alternative built on Node.js, sporting a web GUI"
command="/opt/cronicle/bin/control.sh"
# command_background="yes"


depend() {
    need localmount net
  # need $remote_fs $syslog $named - system log and DNS need to be running
  # syslog-ng could be added to the need list, along with NetworkManager or ConnMan
    provide cronicled
}

start() {
    ebegin "Initialising cronicled..."
    start-stop-daemon --start --exec /opt/cronicle/bin/control.sh start
    eend $?
}

restart() {
    ebegin "Restarting cronicled..."
    start-stop-daemon --start --exec /opt/cronicle/bin/control.sh restart
    eend $?
}

status() {
    ebegin "Retrieving status of cronicled..."
    start-stop-daemon --start --exec /opt/cronicle/bin/control.sh status
    eend $?
}

stop() {
    ebegin "Terminating cronicled..."
    start-stop-daemon --stop --exec /opt/cronicle/bin/control.sh stop
    eend $?
}

If anyone sees any errors in this script, please let me know. I'll be testing it over the next week or so.

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #8
>Or perhaps it was written for a different init system?

I think it's init independent seeing what the top comment explains in control.sh

>Should write a .start and .stop file for the service in question and drop them off in the same folder as local.start ? Just making sure I'm interpreting this information correctly.

I wouldn't advise you to go the local.d route since it doesn't have any service kind of service management, it's basically a glorified binary runner and stopper.

About the script itself, it's not good.

You're basically starting the control script instead of the actual program itself.
You're also defining unnecessary functions like start stop and restart, you don't need that, just define the command variable and OpenRC will take care of it.
Looking at the command variable I'm guessing you're installing cronicle to /opt, I would advise installing to /usr/local .

See an example of an OpenRC service file to get an idea: https://github.com/Lancia-Greggori/lancia-utils/blob/main/openrc-services/dnsmasq

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #9
>Or perhaps it was written for a different init system?

I think it's init independent seeing what the top comment explains in control.sh

>Should write a .start and .stop file for the service in question and drop them off in the same folder as local.start ? Just making sure I'm interpreting this information correctly.

I wouldn't advise you to go the local.d route since it doesn't have any service kind of service management, it's basically a glorified binary runner and stopper.

About the script itself, it's not good.

You're basically starting the control script instead of the actual program itself.
You're also defining unnecessary functions like start stop and restart, you don't need that, just define the command variable and OpenRC will take care of it.
Looking at the command variable I'm guessing you're installing cronicle to /opt, I would advise installing to /usr/local .

See an example of an OpenRC service file to get an idea: https://github.com/Lancia-Greggori/lancia-utils/blob/main/openrc-services/dnsmasq


  • I didn't realize that at all. Am I reinventing the wheel by trying to write an OpenRC script for it, instead of troubleshooting the script it came with?
  • Thank you for letting me know. I'll avoid the local.d option for for this issue.
  • It is definitely a rough draft. When working on it, I did see sources online saying not to use OpenRC to start another script (to start the actual binary instead). I'll have to rip into control.sh to see what it does - especially with the PID file. Cronicle installs itself to /opt by default. Not sure if it supports being installed to a different location, but I'll look into it.
  • I'll review the dnsmasq example in a bit. Thank you for pointing me in the right direction.

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #10
About the script itself, it's not good.

You're basically starting the control script instead of the actual program itself.
You're also defining unnecessary functions like start stop and restart, you don't need that, just define the command variable and OpenRC will take care of it.
Looking at the command variable I'm guessing you're installing cronicle to /opt, I would advise installing to /usr/local .

See an example of an OpenRC service file to get an idea: https://github.com/Lancia-Greggori/lancia-utils/blob/main/openrc-services/dnsmasq


After reviewing the control.sh file that Cronicle uses, I've run into a little trouble creating a proper OpenRC script. The most that I have down is this:
Code: [Select]
#!/sbin/openrc-run
#
# OpenRC script for Cronicle Scheduler
#
# chkconfig: 345 90 10
# description: Cronicle Scheduler

### BEGIN INIT INFO
# Provides: cronicled
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Start/Stop Cronicle Scheduler
### END INIT INFO


NAME="Cronicle Daemon"
DESCRIPTION="A cron alternative built on Node.js, sporting a web GUI"
# COMMAND="/opt/cronicle/bin/control.sh"
PIDFILE=$HOMEDIR/logs/cronicled.pid


depend() {
need localmount net syslog-ng connmand
provide cronicled
}

Everything after this point is questionable. The COMMAND part can't remain as it is because it calls another script. But, when looking at Cronicle's control script (control.sh), this is what I encountered:

Code: [Select]
	case $ARG in
start)
if [ $RUNNING -eq 1 ]; then
echo "$ARG: $NAME already running (pid $PID)"
continue
fi
echo "$0 $ARG: Starting up $NAME..."
if $BINARY ; then
echo "$0 $ARG: $NAME started"
else
echo "$0 $ARG: $NAME could not be started"
ERROR=3
fi
;;
stop)
if [ $RUNNING -eq 0 ]; then
echo "$ARG: $STATUS"
continue
fi
if kill $PID ; then
while [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; do
sleep 1;
done
echo "$0 $ARG: $NAME stopped"
else
echo "$0 $ARG: $NAME could not be stopped"
ERROR=4
fi
;;
restart)
$0 stop start
;;
status)
echo "$ARG: $STATUS"
;;
esac

It's using a bunch of case statements. That alone doesn't trouble me (though I am a newb at this, so maybe it should?). What causes me trouble is how the binary or command gets executed, and what I should set $COMMAND to:

Code: [Select]
	start)
if [ $RUNNING -eq 1 ]; then
echo "$ARG: $NAME already running (pid $PID)"
continue
fi
echo "$0 $ARG: Starting up $NAME..."
if $BINARY ; then
echo "$0 $ARG: $NAME started"
else
echo "$0 $ARG: $NAME could not be started"
ERROR=3
fi
;;
...
...
...
stop)
...
if kill $PID ; then
while [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; do
sleep 1;
done
echo "$0 $ARG: $NAME stopped"

I'm not sure how the start command works at this time. Is it using the $BINARY variable to start the service? I don't think the script is calling itself and tacking an argument to the end, like $0 $ARG , but I could be wrong. The stop command calls kill $PID to kill it by PID. They appear to use two different methods to control the service's execution. Upon first glance, I'm tempted to use $BINARY for $COMMAND. That variable appears to call Node.js and tell it to run main.js. Is that a correct observation?

I'm not sure how to implement the start() and stop() functions for this.

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #11
>I didn't realize that at all. Am I reinventing the wheel by trying to write an OpenRC script for it, instead of troubleshooting the script it came with?

No you're doing the right thing, using an OpenRC service file provides actual service management and supervision compared to the control script

>After reviewing the control.sh file that Cronicle uses, I've run into a little trouble creating a proper OpenRC script. The most that I have down is this:

A big problem with your service file: uppercase variable names
use lowercase because openrc uses lowercase forms of your variables to make decisions

>Is it using the $BINARY variable to start the service?

Yes, that if $BINARY ; then basically means to run the binary, after it finishes executing, execute the codes in the if else statement based on the exit value.

>I'm tempted to use $BINARY for $COMMAND. That variable appears to call Node.js and tell it to run main.js. Is that a correct observation?

Yes, you should use $BINARY for your OpenRC $command variable.

 

Re: Auto-start Cronicle with OpenRC (Troubleshooting)

Reply #12
>I didn't realize that at all. Am I reinventing the wheel by trying to write an OpenRC script for it, instead of troubleshooting the script it came with?

No you're doing the right thing, using an OpenRC service file provides actual service management and supervision compared to the control script

>After reviewing the control.sh file that Cronicle uses, I've run into a little trouble creating a proper OpenRC script. The most that I have down is this:

A big problem with your service file: uppercase variable names
use lowercase because openrc uses lowercase forms of your variables to make decisions

>Is it using the $BINARY variable to start the service?

Yes, that if $BINARY ; then basically means to run the binary, after it finishes executing, execute the codes in the if else statement based on the exit value.

>I'm tempted to use $BINARY for $COMMAND. That variable appears to call Node.js and tell it to run main.js. Is that a correct observation?

Yes, you should use $BINARY for your OpenRC $command variable.


Okay, I've gotten a bit further along with the OpenRC script. More will be coming in the next few hours:
Code: [Select]
#!/sbin/openrc-run
#
# OpenRC script for Cronicle Scheduler
#
# chkconfig: 345 90 10
# description: Cronicle Scheduler

### BEGIN INIT INFO
# Provides: cronicled
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Start/Stop Cronicle Scheduler
### END INIT INFO


### BEGIN CONFIGURATION SECTION
name="cronicled"
description="A cron alternative built on Node.js, sporting a web GUI"
command=$BINARY
# Currently assuming that Cronicle is a well-behaved service that backgrounds itself
# command_background="yes"
pidfile=$HOMEDIR/logs/cronicled.pid

# Starting parameters for Cronicle service
#Long name for the service
lname="Cronicle Daemon"
# home directory -
HOMEDIR="$(dirname "$(cd -- "$(dirname "$0")" && (pwd -P 2>/dev/null || pwd))")"
# nodejs binary, command -
BINARY="node $HOMEDIR/lib/main.js"
# initial runtime values -
ERROR=0
ARGV="$@"
STATUS="Undefined - $name may not have been started yet..."
PACKAGE_VERSION=$(node -p -e "require('./package.json').version")
# The values for RUNNING and PID are set later on...
### END CONFIGURATION SECTION


depend() {
need localmount net syslog-ng connmand
# need $remote_fs $syslog $named - system log and DNS need to be running
# syslog-ng could be added to the need list, along with NetworkManager or ConnMan
provide cronicled
}


start_pre() {
if [ "x$ARGV" = "x" ] ; then
ARGS="help"
fi

for ARG in $@ $ARGS
do
# check for pidfile
if [ -f $pidfile ] ; then
PID=`cat $pidfile`
if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
STATUS="$name is running (pid $PID)"
RUNNING=1
else
STATUS="$name is not running (pid $PID?)"
RUNNING=0
fi
else
STATUS="$name is not running (no pid file)"
RUNNING=0
fi
}


# The start and stop commands are incomplete for now.
# Many sources state not to define start and stop functions...

start() {
ARG="start"
ebegin "Attempting to initialise $name ..."
start-stop-daemon --start --exec $command # Coming soon...
eend $?
}

stop() {
ARG="stop"
ebegin "Attempting to terminate $name ..."
start-stop-daemon --stop --exec # Coming soon...
eend $?
}

status() {
ARG="status"
ebegin "Retrieving status of $name ..."
start-stop-daemon --exec echo "$ARG: $STATUS"
eend $?
}

version() {
ARG="version"
ebegin "Retrieving version of $name ..."
start-stop-daemon --exec echo "$PACKAGE_VERSION"
eend $?
}


Still trying to make sure I write these functions correctly. They look like this in the original control script:
Code: [Select]
# Start snippet
if [ $RUNNING -eq 1 ]; then
echo "$ARG: $lname is already running (pid $PID)"
continue
fi
echo "$0 $ARG: Starting up $lname..."
if $BINARY ; then
echo "$0 $ARG: $lname has started"
else
echo "$0 $ARG: $lname could not be started"
ERROR=3
fi

# Stop snippet
if [ $RUNNING -eq 0 ]; then
echo "$ARG: $STATUS"
continue
fi
if kill $PID ; then
while [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; do
sleep 1;
done
echo "$0 $ARG: $lname has stopped"
else
echo "$0 $ARG: $lname could not be stopped"
ERROR=4
fi

A few questions:
  • Should I ignore most of it and just let OpenRC handle the start/stop commands in this case, since I've defined the $command variable?
  • Should I transplant the contents of the start/stop snippets into the OpenRC script?

From what I've red online, OpenRC can manage PID file management and basic start/stop functionality if I give $command a value. But, not sure if I got bad info.