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

Add system services #311

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions scripts/init/systemd/pulsar.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Unit]
Description=Pulsar security agent
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/pulsard
RestartSec=2
Restart=always
TimeoutStopSec=20

# The service runs as the root user to load eBPF probes
User=root

# Log to syslog
StandardOutput=syslog
StandardError=syslog

[Install]
# Start the service in multi-user mode (runlevels 2, 3, 4, and 5)
WantedBy=multi-user.target
80 changes: 80 additions & 0 deletions scripts/init/sysvinit/pulsar
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: pulsar
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Pulsar security agent
# Description: Pulsar security agent
### END INIT INFO

# Path to the executable
EXEC=/usr/bin/pulsard
# Name of the service
NAME=pulsar
# Logging
LOGFILE=/var/log/${NAME}.log
# PID file location
PIDFILE=/var/run/${NAME}.pid

start() {
echo "Starting $NAME..."
if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
echo "$NAME is already running."
return 1
fi
nohup $EXEC >> $LOGFILE 2>&1 &
echo $! > $PIDFILE
echo "$NAME started."
}

stop() {
echo "Stopping $NAME..."
if [ -f $PIDFILE ]; then
PID=$(cat $PIDFILE)
if kill -0 $PID; then
kill $PID
rm -f $PIDFILE
echo "$NAME stopped."
else
echo "$NAME is not running."
fi
else
echo "$NAME PID file not found, $NAME may not be running."
fi
}

restart() {
stop
start
}

status() {
if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
echo "$NAME is running."
else
echo "$NAME is not running."
fi
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

exit 0