generated from The-LukeZ/discordjs-app-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Synchronize Votes
LukeZ edited this page Apr 2, 2025
·
3 revisions
Important
-
If you have not already done that, follow the instructions on the Main Page for Synchronizing Things.
-
If you named the
local.conf
file anything else butlocal.conf
, you NEED to configure the.service
file like explained below.
If you did something unlike the example stated, please continue reading from here. Otherwise, you can continue below.
[Unit]
Description=Not Supportmail - Sync Votes
[Service]
User=not-supportmail # Important: This should be the user that owns the Discord bot files (e.g., /etc/not-supportmail/).
WorkingDirectory=/etc/discord-bot/ # Sets the bot's working directory.
ExecStart=/usr/bin/npm run cron:sync-votes # Command to start the vote synchronization script.
Restart=always # If the script crashes, systemd will automatically restart it.
EnvironmentFile=/etc/discord-bot/local.conf # Load environment variables from this file (rename if your file is different).
[Install]
WantedBy=multi-user.target # Makes the service start when the system reaches the multi-user state (normal operation).
-
Description
: A concise description of the service. -
User
: Crucial! Ensure the username here matches the user who owns the/etc/not-supportmail/
directory and has the necessary permissions to run the bot. -
WorkingDirectory
: This tells systemd where to execute theExecStart
command from. -
ExecStart
: This is the command that actually runs your vote synchronization script. It assumes you are usingnpm
. Adjust if you use a different package manager or command. -
Restart=always
: This is useful for ensuring your bot automatically recovers if it encounters an error. -
EnvironmentFile
: This line points to the file containing your bot's configuration, such as API keys or database credentials. Make sure the path and filename are correct! -
WantedBy=multi-user.target
: This standard setting ensures the service starts when your server is generally ready.
[Unit]
Description=Not Supportmail - Hourly Vote Sync
[Timer]
OnUnitActiveSec=1h # Run the service 1 hour after it was last active (finished).
AccuracySec=1min # Systemd will try to start the service within a 1-minute window of the scheduled time.
Unit=sync-votes.service # Important! This must be the exact filename of your service file from above.
[Install]
WantedBy=timers.target # Makes the timer start when the system's timers are activated.
-
Description
: A brief description of the timer. -
OnUnitActiveSec=1h
: This sets the timer to trigger the associated service every hour after the service has finished its previous run. If you want it to run every hour regardless of the previous run's duration, you might considerOnCalendar=*:0/1
. -
AccuracySec=1min
: This defines how precisely systemd should try to start the service. -
Unit
: Critical! This line links the timer to the service file. The name must match the.service
file name exactly. -
WantedBy=timers.target
: This standard setting ensures the timer starts when the system manages timers.
Remember to replace /etc/not-supportmail/
, not-supportmail
, local.conf
with your actual path, user, config file name!
Since you now configured, gave the correct permissions and named everything correctly, you have to run the commands to actually enable the timer on system start and start it right away. An example is shown below - make sure to use your own correct file paths and -names.
systemctl enable not-supportmail
systemctl start not-supportmail