Okay, this script writing for sysv is much more complex than sysd.
Following this source, I tried writing this as the script: /etc/init.d/etesync-dav.service:
#!/bin/sh
#### BEGIN INIT INFO
## Provides: etesync-dav
## Required-Start: $local_fs $remote_fs
## Required-Stop: $local_fs $remote_fs
## Default-Start: 2 3 4 5
## Default-Stop: 0 1 6
## Short Description: ## Short-Description: Start and stop the etesync-dav service
#### END INIT INFO
start() {
## Start the service
/usr/local/bin start
}
stop() {
## Stop the service
/usr/local/bin stop
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: etesync-dav {start|stop|restart}"
exit 1
;;
esac
exit 0
The source article had a lot of fancy things that I did not need in the script (i.e., “echo”) and a few I did not understand their purpose. So let’s compare the sample script with my additions/changes:
#!/bin/bash
## chkconfig: 2345 99 01
## description: PM2 is a process manager for Node.js applications.
. /etc/init.d/functions
PM2_HOME="/root/.pm2"
PM2_BIN="$(which pm2)"
start() {
echo "Starting PM2"
if [ -f "$PM2_HOME/pm2.pid" ]; then
echo "PM2 is already running"
exit 1
fi
$PM2_BIN start
}
stop() {
echo "Stopping PM2"
$PM2_BIN stop
}
restart() {
echo "Restarting PM2"
$PM2_BIN restart
}
status() {
$PM2_BIN list
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $?
The only things I knew to add were the location of the service (not the script) “etesync-dav” and the name of the service: “etesync-dav.”
For the next step:
To install the service, make the init script executable and copy it to the /etc/init.d directory:
chmod +x /path/to/service_name
cp /path/to/service_name /etc/init.d/
The first command was similar to what I did in systemd. Note that I left the service file itself where I was originally told to have it. Thus, using the “path to service” of where that file is located now. But since I had already moved the service file to /etc/init.d, I did not do the second command.
Yet running
service etesync-dav start
says unrecognized service.
So what am I doing wrong in this scenario?
This is the instruction for (systemd) installing & auto starting etesync-dav and which I first completed in an attempt to get it running:
Download & Run
To download the DAV, head over to the releases page and download the linux-amd64-etesync-dav file.
Next we open up a terminal, change our directory to downloads, give the file execute permissions and we can then run for the first time.
$ cd ~/Downloads
$ chmod +x linux-amd64-etesync-dav
$ ./linux-amd64-etesync-dav
You should now be able to surf to http://localhost:37358/.web/login/, where you will be greeted by a login screen.
Of course, I cannot surf to my account to login as the service is not running yet.
Then the autostart:
Next up, we want to make sure that this program is always started whenever we boot our computer. To do that, we will be using a systemd file.
First, move the binary file to the /usr/local/bin
folder.
$ mv linux-amd64-etesync-dav /usr/local/bin/etesync-dav
Next, we create a file called etesync-dav.service
. You can place this file anywhere for now. In the file, you should insert the following:
[Unit]
Description=Cal/CardDAV frontend for Etesync
[Service]
Type=simple
ExecStart=/usr/local/bin/etesync-dav
[Install]
WantedBy=default.target
Concretely, this is a systemd service file that lets systemd know that we want it to execute the etesync-dav
file in /usr/local/bin
. For systemd to see this file, we need to move it first (you might need sudo for this). After moving the file, we will tell systemd to (a) run the program at boot, and (b) run the program now
$ sudo mv etesync-dav.service /usr/lib/systemd/user/etesync-dav.service
$ systemctl --user enable etesync-dav
$ systemctl --user start etesync-dav
The name of the file I downloaded is: linux-amd64-etesync-dav. And that is what I moved to /usr/local/bin where now resides: etesync-dav.
It’s been a long day working and I figured I could at least give it a go before retiring for the evening. Any help much appreciated.
Thanks,
Sheila