During persecution, enduring perhaps horrible suffering, a Christian should do good. In reality, that is what makes him a Christian. He must rise above his situation and continue to carry out acts of love, even toward his persecutors. It is part of Jesus' Sermon on the Mount: "But I say to you, love your enemies, bless those who curse you, do good to those who hate you, and pray for those who spitefully use you and persecute you, that you may be sons of your Father in heaven" (Matthew 5:44-45).
During His crucifixion, Jesus practiced what He had preached, continuing to preach the gospel of the Kingdom to His dying breath. He comforted the daughters of Jerusalem (Luke 23:27-31) and promised the thief next to him an opportunity for salvation (verses 39-43). He also asked His Father to forgive His murderers (verse 34). No matter what the circumstances, He never stopped showing love to all, even to His enemies. Paul imitated this example, boldly preaching the gospel while in chains, and doing so actually furthered the cause of the gospel rather than hindered it (Philippians 1:12-18).
Additionally, we must have an attitude of joy. Again, it is Peter who advises us: "Beloved, do not think it strange concerning the fiery trial which is to try you, as though some strange thing happened to you. But rejoice to the extent that you partake of Christ's sufferings, that when His glory is revealed, you may also be glad with exceeding joy" (I Peter 4:12-13).
This is a tough order, but it is not impossible. However, notice that he includes a qualification on this, that we are to be joyful if we are suffering for a righteous reason, sharing Christ's sufferings. But if we suffer from our own stupidity, we need to repent!
James tells us in James 1:2, "Count it all joy when you fall into various trials." It is not natural to rejoice in the midst of suffering, but we can do it because the Holy Spirit is working in us, giving us God's perspective and strength to endure (see I Peter 1:3-9). That is the only way we can rejoice in suffering, knowing that God has counted us worthy of it.
Obviously, no one wants to be persecuted, but "all who desire to live godly in Christ Jesus will suffer persecution" (II Timothy 3:12). Yet, if we do, we have Christ's promise that it is for our good: "Blessed are those who are persecuted for righteousness' sake, for theirs is the kingdom of heaven" (Matthew 5:10).